mity / md4c

C Markdown parser. Fast. SAX-like interface. Compliant to CommonMark specification.
MIT License
759 stars 140 forks source link

Refactor: Build the HTML renderer as a standalone library #89

Closed mity closed 4 years ago

mity commented 4 years ago

(Addresses #82)

Current status:

Right now I see it as a fairly complete, yet it is currently meant more as a proof of concept and material for further discussion. So feedback is welcome.

Aims:

  1. Make the HTML renderer build as a standalone library (stable public API, pkgconfig .pc file etc.).
  2. Provide simpler interface for applications which need only the Markdown -> HTML conversion.
  3. Should serve also as a model for renderers to other formats if/when those are implemented and added.

Notes:

  1. It involves renaming the render_html.[ch] to md_html.[ch] and the identifiers from the header to make it more friendly/consistent as a public API.

  2. It involves moving all all potentially reusable sources into a single (flat) src directory.

    Rationale: Generally I prefer one-target-per-directory structure, but it imho does not work/scale well here. If we add more renderers, each with one directory and containing (likely/in most cases) just one header and one source, yet they would still likely need to reuse the entity.[ch].

  3. Application should not need more then the parser flags from md4c.h. Strictly speaking, we might consider make it complete independent header and make the renderer translate its flags to the parser flags.

    Disadvantage would be that then every (future) renderer whould then have do the same kind of translation for the sake of consistency.

    Advantage would be that renderers could implement or enforce/disable some flags if they do not/cannot implement some MD4C features and communicate it better in their API. For example I can imagine that most renderers (likely all but the HTML one) will never support the raw HTML blocks/inlines.

    I am not sure what is better here.

mity commented 4 years ago

(Rebased the PR to make it up-to-date with the current master.)

mity commented 4 years ago

(Rebased the PR on top of the current master.)

codecov[bot] commented 4 years ago

Codecov Report

Merging #89 into master will increase coverage by 0.09%. The diff coverage is 92.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #89      +/-   ##
==========================================
+ Coverage   94.22%   94.31%   +0.09%     
==========================================
  Files           1        3       +2     
  Lines        2803     3059     +256     
==========================================
+ Hits         2641     2885     +244     
- Misses        162      174      +12     
Impacted Files Coverage Δ
src/entity.c 100.00% <ø> (ø)
src/md4c.c 94.22% <ø> (ø)
src/md4c-html.c 95.18% <92.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update f9da199...711fff1. Read the comment docs.