Closed EcutDavid closed 7 years ago
Currently, the result file is converted based on form data, and the original file.
form data
Code in Editor
Editor
updateResult(formData) { const { content, fileIndex, filesMeta, schema, updateFile } = this.props let markdownText = content const docConfigObj = parseYamlInsideMarkdown(markdownText) if(!docConfigObj) return const schemaObj = schema.properties for (let i = 0; i < schemaObj.length; i++) { const linePattern = new RegExp(schemaObj[i].target + ': ?[\\w 、\/]*') const prePattern = new RegExp(schemaObj[i].target + ': ?') let newValue = formData[schemaObj[i].name] const preText = prePattern.exec(markdownText)[0] markdownText = markdownText.replace(linePattern, preText + newValue) } const targetContent = retriveContent(markdownText) this.setState({ resultMarkdown: markdownText, targetContent }) updateFile(filesMeta[fileIndex].path, markdownText + targetContent) }
We have to replace the regexp stuff to something like JSON.stringfy.
JSON.stringfy
Because current regexp just support yaml like
--- a: b c: d e: f ---
But yaml with array values won't supported.
--- a: b c: - j - k e: f ---
I'm using js-yaml for parse yaml const doc = yaml.safeLoad(text)(https://github.com/Wiredcraft/jekyllplus/blob/6eb6f13cd7f8d5ff1e0fe735919fc5524f8404cc/client/src/helpers/markdown.js#L35)
js-yaml
const doc = yaml.safeLoad(text)
Maybe they also support dump the js object to yaml(https://github.com/nodeca/js-yaml).
Not relevant any more, closing
Currently, the result file is converted based on
form data
, and the original file.Code in
Editor
We have to replace the regexp stuff to something like
JSON.stringfy
.Because current regexp just support yaml like
But yaml with array values won't supported.
I'm using
js-yaml
for parse yamlconst doc = yaml.safeLoad(text)
(https://github.com/Wiredcraft/jekyllplus/blob/6eb6f13cd7f8d5ff1e0fe735919fc5524f8404cc/client/src/helpers/markdown.js#L35)Maybe they also support dump the js object to yaml(https://github.com/nodeca/js-yaml).