breck7 / scroll

Scroll is a language for scientists of all ages. Scroll includes a command line app that builds static blogs, websites, CSVs, text files, and more.
https://scroll.pub
Other
445 stars 18 forks source link

Custom markup symbols (bold/italic) instead of the defaults #122

Closed eugenesvk closed 3 months ago

eugenesvk commented 3 months ago

Is Scroll flexible enough to allow Parsers to be extended to replace the default markup symbols?

For example, I'd like the asterisk to just be an actual asterisk and use something else for bold

Or make the underline used for underlining text and something else for italics?

breck7 commented 3 months ago

I'd like the asterisk to just be an actual asterisk

Yes, but the documentation for that is not good yet.

Demo:

http://hub.scroll.pub/edit.html?folderName=asteriskdemo&fileName=index.scroll&password=homeamsomefindnewsnew

use something else for bold...Or make the underline used for underlining text and something else for italics?

Yes, the aftertext directives can be added/expanded easily. In theory. In practice that code is a bit messy and it's on my todo list to clean it up. But you can absolutely bank on it that this is not only possible but is possible and will be very easy in later versions.

eugenesvk commented 3 months ago

The demo is for overriding asterisks as a prefix, but I only meant asterisks as used in the *bold* paired markup

will be very easy in later versions.

So that could be a "global" override instead of being used for every piece of text (as far as I understand from https://breckyunits.com/aftertext.html)?

Similarly to how your demo allows a global override of the asterisk as a prefix

breck7 commented 3 months ago

but I only meant asterisks as used in the bold paired markup

Oh that makes sense. Sorry I read it wrong.

The relevant line of source code is https://github.com/breck7/scroll/blob/e20dc4a0ddb87db82eb377e8c5967f7297bc3f2e/parsers/aftertext.parsers#L216

I can clean this code up soon to make it easier to accomplish what you want. Good idea!

eugenesvk commented 3 months ago

Would be nice indeed if all one had to do was something like "substitute wrapsOnParser" and just change this one const wraps with custom delimiters, while leaving all existing rules as is (and when you update the inner rules this custom substitution would benefit from that as well), and it would work everywhere wrapsOnParser is used in the current parsers

For example, I see that here is wrapParser that extends wrapsOnParser, guess it should continue to work? Or maybe this could lead to issues with priorities? For example, this wrapParser as far as I understand defines _ as an italic marker, but in my example I've replaced wrapsOnParser to use _ as an underline marker, so which parser would win?

breck7 commented 3 months ago

Okay. I added a inlineMarkups parser. Would love to hear what you think @eugenesvk

https://try.scroll.pub/#scroll%0A%20thinColumns%201%0A%20gazetteCss%0A%20%0A%20inlineMarkups%0A%20%20*%0A%20%20%20%2F%2F%20disable%20bold%0A%20%20_%20u%0A%20%20%20%2F%2F%20override%20underline%0A%20%20~~~%20marquee%0A%20%20%20%2F%2F%20Add%20marquee!%0A%20%0A%20*This*%20should%20not%20be%20bold.%20~~~This%20should%20be%20a%20marquee.~~~%20And%20_this_%20should%20be%20underlined.%0A%20%0A%20

eugenesvk commented 3 months ago

Looks great, and even nested markup works, playground example! Though for some reason /a//b/ instead of 2 italicized letters prints a/<>b, couldn't find the reason and how escaping works

(triple symbol works, but isn't a proper escape since

`a```b`

while printing

a`b

doesn't surround the actual backtick in "code" highlight? So how would you escape the default or custom marker?

breck7 commented 3 months ago

Looks great, and even nested markup works

Great to hear!

(triple symbol works, but isn't a proper escape since So how would you escape the default or custom marker?

I've found I rarely need escapes, and in those cases I just use a code parser or disable the conflicting markups, or use a raw html div <div>. Seems to work great, and keeps things simple for most cases.

If one needed escapes a lot, I'd probably suggest building one's own paragraph parser perhaps.

breck7 commented 3 months ago

One more feature: added support for attributes.

https://try.scroll.pub/#scroll%0A%20gazetteCss%0A%20%0A%20Custom%20markups%20now%20accept%20attributes.%0A%20%0A%20inlineMarkups%0A%20%20%2F%2F%20delimiter%20tag%20%5Battributes%5D%0A%20%20%40%20button%20class%3D%22button%22%0A%20%0A%20Make%20this%20a%20%40button%40%0A%20%0A%20css%0A%20%20.button%20%7B%0A%20%20background-color%3A%20%234CAF50%3B%0A%20%20border%3A%20none%3B%0A%20%20color%3A%20white%3B%0A%20%20padding%3A%205px%2010px%3B%0A%20%20text-align%3A%20center%3B%0A%20%20cursor%3A%20pointer%3B%0A%20%20border-radius%3A%2012px%3B%0A%20%20%7D%0A%20