Naviga Writer
6.3.3
6.3.3
  • Naviga Writer
  • Release notes
    • 6.3.3
    • 6.3.2
    • 6.3.1
    • 6.2.1
    • 6.2.0
    • 6.1.2
    • 6.1.1
    • 6.1.0
    • 6.0.0
    • 5.3.0
  • Introduction
    • Authoring
    • Developing
    • Publishing
    • User stories and reference cases
  • User Guide
    • Writer User Guide
      • The Content Area and Tabs
        • Help menu
        • Language menu
        • Article name
        • Writing teasers
        • Content area
        • Information
        • Search and replace words
        • History Button
        • Save and publish flow
        • Tabs
          • Meta Tab
            • Author
            • Channels
          • Integrations Tab
          • Image and Article search Tab
        • Locked article
      • Text management
      • Writer Keyboard Shortcuts
      • Personal Writer template
      • Channels to control access
      • Images User Guide
      • Common questions when starting using Writer
  • Admin Guide
    • Configuration files
    • Configurations Guide
    • Configuration of Writer templates
    • Publish Flow
      • Default configuration definitions
      • Starting part of the configuration
      • Publish flow config details
      • Configuration of calendarLocale
      • Preconditions for roles in the publish flow
    • Generic properties for Objects
      • Generic properties configuration
    • Image Services
      • Photo uploader
      • Binary Service Light
      • ImEngine
      • Imgix
    • Available Plugins
      • Naviga developed plugins
        • Plugins in earlier versions of Writer
      • Third-party plugins
  • Developer guide
    • Writer plugin development
      • Quickstart
      • Plugin overview
      • Creating an content object plugin
      • Validation and hooks
      • Interacting with external resources
    • Writer Plugin Building Blocks
      • Package
      • Component
      • Node
      • Converter
      • Events
    • Writer plugin style guide
      • CSS Guidelines
      • CSS variables, colors and fonts
      • UI Components
    • Tutorials
      • Popover & text analysis
      • Search & replace
      • Concept interaction
    • Infomaker NewsML
      • Overview
      • Document relations and types
      • Extensions XSD
      • NewsItem
      • ConceptItem
      • PlanningItem
      • Examples
        • NewsItem - Text
        • NewsItem - Picture
        • NewsItem - PDF
        • ConceptItem - Author
        • ConceptItem - Category
        • ConceptItem - Channel
        • ConceptItem - Content Profile
        • ConceptItem - Event
        • ConceptItem - Organisation
        • ConceptItem - Person
        • ConceptItem - Place (point)](point)](point)](point)](point)](point)](point)](point)](point)](point)]
        • ConceptItem - Place (polygon)](polygon)](polygon)](polygon)](polygon)](polygon)](polygon)](polygon)]
        • ConceptItem - Section
        • ConceptItem - Story
        • ConceptItem - Topic
        • PlanningItem
    • Media Enrichment
      • Images
  • API Reference
    • Writer Api
      • Api
      • Article
      • Browser
      • Concept
      • ConceptService
      • Document
      • Events
      • NewsItem
      • Router
      • Ui
      • Upload
      • User
      • settings
    • UI Components
      • UIAvatar
      • UIButton
      • UIByline
      • UICheckbox
      • UIChip
      • UIDatePicker
      • UIDatetimeFieldEditor
      • UIDropdown
      • UIFieldEditor
      • UIIconButton
      • UIInlineImage
      • UIPagination
      • UISelect
      • UITimePicker
      • UIToggle
      • UITooltip
      • UIInputText
      • UITextarea
Powered by GitBook
On this page

Was this helpful?

  1. Developer guide
  2. Writer Plugin Building Blocks

Converter

PreviousNodeNextEvents

Last updated 5 years ago

Was this helpful?

While a user has an article open for editing in the Writer, it is represented in the Browser as a collection of nodes with text content and attributes. Everytime the article is to be sent or read from the article repository, it needs to be translated to an XML representation. The XML document structure for an article is well defined by the format specification.

The process of converting to/from nodes and XML is done by Writer, but it takes help from one or many converters. Example of plugins that provide converters are plugins that contribute content to the article text, or add metadata information about the article.

Conversion process from XML document to nodes in Browser

Telling Writer about your converter

// MyPluginPackage.js

import {converter} from './MyPluginConverter'

export default {
    name: 'myplugin',
    id: 'com.example.myplugin',
    version: '1.0.0',
    configure(configurator) {
        configurator.addConverter('newsml', converter)
    }
}

The converter should contain a function for converting data from XML to Substance Nodes, called import, and one function for converting from Substance Nodes to XML, called export. Here's an example where the plugin called myplugin is adding content to the article, through the object extension in the writer format. In this example, the plugin implements an object where it is possible to define a question and provide an answer.

The converter can also contain a function matchElement, to let it know if it's responsible for the current node.

// MyPluginConverter.js

const MyPluginConverter = {
    type: 'myplugin',
    tagName: 'object',

    matchElement: function (el) {
        return el.is('object') && el.attr('type') === 'myplugin'
    },

    /**
     * Responsible for converting data from XML to a node in Browser
     */
    import: function (xmlElement, node) {
        node.question = xmlElement.attr('question')
        node.answer = xmlElement.attr('answer')
    },

    /**
     * Responsible for converting data from nodes to XML
     */
    export: function(node, xmlElement) {
        xmlElement.attr({
            question: node.question,
            answer: node.answer
        })
    }
}

export {MyPluginConverter}

An article example with the plugin1 active could look like:

<!-- In this interview series, we have found that the number one answer to our specific question is: -->
<object type="myplugin" question="Do you like hotdogs?" answer="yes, I do"/>

The way to tell Writer that there's a converter to be used for a plugin, is to register it in the package file for the plugin. . In the example below, a plugin with the name plugin is registering a converter that is defined in the MyPluginConverter.js file

Read more about the Package file
newsitem-text.xml