npm / marky-markdown

npm's markdown parser
https://www.npmjs.com/package/@npmcorp/marky-markdown
405 stars 71 forks source link

[WIP] Add formatting based on lang for html_blocks #419

Closed karanjthakkar closed 6 years ago

karanjthakkar commented 7 years ago

@revin The existing README highlighting for oojs: https://npm.im/oojs The fixed highlighting after this change: https://auspicious-thread.surge.sh

Approach:

  1. Add a plugin which overrides the html_block renderer
  2. If a pre tag is available with, it checks if the lang is javascript/bash. (Couldnt find a more comprehensive list of supported langs but new ones can be added without issues)
  3. Extract content from the html block
  4. Replace token content with this
  5. calls the parent html_block renderer and then uses the code from https://github.com/npm/marky-markdown/blob/master/lib/plugin/code-wrap.js to wrap this generated html into a code highlighting wrapper

Overall this seems to fix the issue. I'd like to get your feedback on whether I solved it in the right way. Also, I'm a little confused as to how I should go about adding tests for this. Any help/advice would be appreciated.


Fixes #402

karanjthakkar commented 6 years ago

Bump.