janet-lang / spork

Various Janet utility modules - the official "Contrib" library.
MIT License
123 stars 35 forks source link

spork/mdz eats whitespace #175

Open iacore opened 9 months ago

iacore commented 9 months ago

how to reproduce

(import spork/mdz)
(mdz/markup (slurp "doc/data.mdz"))

now, you should see this output

@{:current-file "<anonymous>" :front-matter { :author "Caleb Figgers" :license "MIT" :order 1 :template "mdzdoc/main.html" :title "data"} :markup-dom @[ "\n" (:a {"href" "https://clojure.org/"} @[@["Clojure"]]) (:p "contains a very useful core library (or \"namespace\" in Clojure parlance) called "

the space between Clojure is and contains is gone!

Also, the :a tag should be inside :p tag, not before it.

sogaiu commented 9 months ago

I was able to reproduce, i.e. I noticed the lack of a space and the :p tag behavior doesn't seem appropriate.

Fixes would be nice :)


A couple of work-arounds [1]:

I'm not suggesting that it wouldn't be better for the current behavior to be improved, the above are just interim alternatives that seem to yield improved results. If one is willing to modify one's content, may be one or the other is useful.


[1] Limited testing with either of the work-around via:

(htmlgen/html (get (mdz/markup (slurp "file.mdz")) :markup-dom))

seemed to yield ok results here.

bakpakin commented 6 months ago

So this is something that has been in mendoza since the beginning and not sure the best way to resolve it - starting a section with a tag is ambiguous in that some tags are "inline" and some tags are block elements. I think the recommended work around of using @p{...} is the right thing here, but aside from creating complicated parsing rules, I might just leave this as wontfix.

sogaiu commented 6 months ago

If there's no good way to address this, may be some kind of mention in documentation could be helpful?

iacore commented 6 months ago

complicated parsing rules

I thought of a rule, which states,


Any group of elements with an empty line before and after,

if it's only one element, it's not wrapped in <p>

otherwise, it is wrapped in <p>

@link[]() this is in a paragraph

this is in a paragraph @link[]()

@link[this is not in a paragraph but should be in a paragraph?]()

@codeblock`this is not in a paragraph`

What existing code does this break?