jgm / lcmark

Flexible CommonMark converter
BSD 2-Clause "Simplified" License
55 stars 6 forks source link

Preserve non-string metadata types #10

Closed RiskoZoSlovenska closed 2 years ago

RiskoZoSlovenska commented 2 years ago

Current behaviour parses each leaf node of the metadata as a CommonMark string, which doesn't make sense for data types such as nulls and booleans (and can lead to surprising behaviour).

This pull request limits CommonMark parsing to only string nodes to allow numbers, booleans, nulls, etc. in the metadata. cmark nodes are then differentiated from other nodes using a type() == "userdata" check (I am not sure whether there is a better way to check whether something is a cmark node).

Although this is a pretty breaking change, it passes all the tests.

Progresses https://github.com/jgm/lcmark/issues/8.

See comment below.

RiskoZoSlovenska commented 2 years ago

Upon reading the README more carefully, I realized that non-string leaf nodes aren't officially supported. This means that the change isn't as breaking as I thought (since behaviour isn't formally defined for non-string leaves) and thus this PR is now more of a feature than a fix.