Skip to content

Commit

Permalink
Exported notes contain plaintext and html
Browse files Browse the repository at this point in the history
  • Loading branch information
styts authored and inukshuk committed Dec 6, 2017
1 parent 96f1e8c commit f201973
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/export/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
const { promises: jsonld } = require('jsonld')

const { pick, pluck } = require('../common/util')
const { ITEM, PHOTO, SELECTION, NOTE } = require('../constants/type')
const { ITEM, PHOTO, SELECTION } = require('../constants/type')
const makeNote = require('./note')

const TR = 'https://tropy.org/v1/tropy#'

Expand Down Expand Up @@ -84,15 +85,6 @@ function addInfo(target, ids, key, state, fn = x => x.name) {
return target
}

function makeNote(note) {
return {
'@type': NOTE,
'text': note.text,
'doc': JSON.stringify(note.state.doc),
'language': note.language
}
}

function addSelections(template, photo, ids, resources) {
const selProps = ['x', 'y', 'width', 'height', 'angle', 'mirror', 'template']
const [props, metadata,,,, notes, selections] = resources
Expand Down
23 changes: 23 additions & 0 deletions src/export/note.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'

const { NOTE } = require('../constants/type')

const { DOMSerializer } = require('prosemirror-model')
const { schema } = require('../components/editor/schema')

const serializer = DOMSerializer.fromSchema(schema)

function toHTML(doc) {
const node = schema.nodeFromJSON(doc)
const docFragment = serializer.serializeFragment(node)
return Array.from(docFragment.children).map(x => x.outerHTML).join('')
}

module.exports = function (note) {
return {
'@type': NOTE,
'text': note.text,
'html': toHTML(note.state.doc),
'language': note.language
}
}

0 comments on commit f201973

Please sign in to comment.