markdown-json icon indicating copy to clipboard operation
markdown-json copied to clipboard

Parse Markdown Strings to Json Object

Open yonderbread opened this issue 5 years ago • 7 comments
trafficstars

Instead of reading in files, would I be able to parse some strings with this and convert them to objects?

yonderbread avatar Sep 04 '20 19:09 yonderbread

@yonderbread , thanks for the suggestion. Could you please give more details about the string input usage?

klaytonfaria avatar Sep 28 '20 16:09 klaytonfaria

Yea of course, so instead of reading directly from a file object you could just pass an already read out file as a string to markdown-json and it would return the Object version of it.

yonderbread avatar Sep 30 '20 05:09 yonderbread

Same sentiment from me - I wasn't looking for a server/file processor - I just wanted a function that would convert a markdown string to a JSON structure.

e.g.:

const markdownJson = require('markdown-json')
const fs = require('fs')
const markdown = fs.readFileSync('README.md', 'utf8')
const json = markdownJson.parse(markdown)
console.log(json)

johnbeech avatar Sep 10 '21 09:09 johnbeech

Same sentiment from me - I wasn't looking for a server/file processor - I just wanted a function that would convert a markdown string to a JSON structure.

e.g.:

const markdownJson = require('markdown-json')
const fs = require('fs')
const markdown = fs.readFileSync('README.md', 'utf8')
const json = markdownJson.parse(markdown)
console.log(json)

Yup. That's what I remember wanting to do as well. If I find some time I will try to implement this into the library.

yonderbread avatar Sep 13 '21 16:09 yonderbread

maybe this is solution to not convert markdown to html

  1. Open lib/generator.js
  2. Edit line 125
  3. Give comment // .use(markdown())
  4. Save and run again

uarefans avatar Mar 03 '22 22:03 uarefans

Gonna try to test some things out. Feel free to open a pull request on my fork.

yonderbread avatar Mar 14 '22 22:03 yonderbread

Gonna try to test some things out. Feel free to open a pull request on my fork.

not

//.use(writeJson)

but

 // .use(markdown())

Reference your file at line 123 and please test delete all generator.js and run node markdown-json again, you give error or not. This is important because if not show any error you are using global markdown-json not from github but from npm install markdown-json.

reinstall with

git clone https://github.com/klaytonfaria/markdown-json.git
cd markdown-json
npm install
edit lib/generator.js
node markdown-json

uarefans avatar Apr 14 '22 14:04 uarefans