Is it possible to make markdown editor always store HTML in DB side ?



  • Is it possible to make markdown editor always store HTML in DB side when post/update a post ?

    because I have to analysis the content by jquery(jsdom) in server side.


  • Community Rep

    That's... interesting, what's your use case?



  • @BDHarrington7 thanks for reply, we have two scenarios currently:

    • index the post content into search energy(elasticsearch). Because markdown content has some redundant character like(#, >) which we don't want to index.
      Worse is when the post has code snippet, the syntax prefix words will be indexed as well. like(```` javascript) which disturbs searching.

    • we want to extract some specified code snippets(like ```` mycode ) then do some analysis logic. I know this could be done by using regex, but we already have html parser in production (jquery)


  • GNU/Linux

    Since there isn't any (didn't search for it thought. but for sure nothing loss-less possible) inverse-compiler html to markdown you wouldn't be able to edit your posts afterwards using markdown.

    Maybe you'd like to write a plugin to listen for post-updates/-creations, compile it (probably using the NodeBB hook filter:parse.post) and save it alongside within the db.
    This way it only suffers on space usage (using redis this may cause RAM space issues thought, depends on your board size and RAM space).
    Since this attempt doesn't change the original data, NodeBB's functionality won't be altered.


  • Admin

    Yes, I'd also go with what @frissdiegurke suggested. We don't normally store HTML in the database because Markdown->HTML is not losslessly reversible (if that is the right term...). So there's a need to save the user input in the same format that the user entered it to begin with, and to minimise the alternations, if any.


  • Community Rep

    If you just need it in the html form when you index it, you can do some processing (markdown to html) after getting the data from the hook that was mentioned above



  • @frissdiegurke @julian @BDHarrington7

    thanks everyone, sounds store HTML in DB separately is a good idear.

    BTW: I found a markdown to html parser in npm(markdown), it looks greate. Any other suggestion is appreciated.


  • Admin

    Your best bet might to just be calling plugins.fireHook('filter:parse.post'); 😄


Log in to reply
 


Looks like your connection to NodeBB was lost, please wait while we try to reconnect.