Allow spaces in inline elements with MarkoJS concise markup - marko

We are using MarkoJS in our new project. I love concise scrypts but in MarkoJS it seems they trim all possible spaces.
The example is:
h1
-- hello
span
-- Diego!
Outputs:
<h1>Hello<span>Diego!</span></h1>
This output is very similar to HAML's trailing trims command "<". Even after reading the docs, I cannot find a way to leave any inline element defined with concise lang to not trim the trailing space like this:
Outputs:
<h1>Hello <span>Diego!</span> </h1>

Where whitespace is important I would suggest using the non-concise syntax since Marko allows you to mix and match the HTML syntax and the concise syntax. For example:
div -- This is concise
<h1>Hello <span>Diego!</span> </h1>
div -- Back to concise
This will produce the following output:
<div>This is concise</div>
<h1>Hello <span>Diego!</span> </h1>
<div>Back to concise</div>
Here's another alternative:
div -- This is concise
h1 -- Hello <span>Diego!</span>
div -- Back to concise
However, that produces a slightly different output that may or may not be what you are looking for:
<div>This is concise</div>
<h1>Hello <span>Diego!</span></h1>
<div>Back to concise</div>
FWIW, it's usually not a good idea to leave trailing whitespace in your source files since the intentions will not be obvious to someone who is just looking at the text (some editors such as Atom will strip out trailing whitespace on save by default).
Hope that works for you.

Related

Using sed - how to replace two HTML tags or patterns with unknown content in-between?

I want to leave the unknown content between tags intact, but want to match all tags that use:
<div class="section1-title">arbitrary content here</div>
and replace the surrounding tags with:
<h2>arbitrary content here</h2>
I've come up with the following, but obviously it's not working as in the second part it's literally substituting "].*[<]/h2[>]" for each match found.
sed -i 's/[<]div class=\"section1-title\"[>].*[<]\/div[>]/<h2[>].*[<]\/h2[>]/g'
I'd like to specifically know how to leave that middle content intact, no matter what is in there, and just match those surrounding tags as obviously there are quite a few elements with so I can't just separately search & replace them. The first part of the sed statement does seem to match the right content as far as I can tell, it's mostly part 2 that I'm unsure of.
What you need is a backref.
bash-3.2$ sed 's/<div class=\"section1-title\">\(.*\)
<\/div>/<h2>\1<\/h2>/g' <<< '<div class="section1-title">arbitrary
content here</div>'
<h2>arbitrary content here</h2>
The parentheses around your content - \(.*\) - allow it to be referenced later as is with the \1.
See: https://www.regular-expressions.info/backref.html
and .bash_profile sed: \1 not defined in the RE for an explanation about why the parentheses should be escaped in your regex.

mathjax commas in digits

This is a TeX legacy issue---it would have made more sense to require a whitespace when a whitespace is desired: 12,123 is probably a number, while 12, 123 is probably a list. Alas, it is what it is.
Related to MathJax rendering of commas in numbers, where the solution is suppression of spaces via {,}. Works, but inconvenient. Is there a way to make this automatic?
The hack in https://github.com/mathjax/MathJax/issues/169#issuecomment-2040235 is concerned with European vs Anglo. The equivalent hack,
<script type="text/x-mathjax-config">
MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
MathJax.InputJax.TeX.Definitions.number =
/^(?:[0-9]+(?:\,[0-9]{3})*(?:\{\.\}[0-9]*)*|\{\.\}[0-9]+)/
});
</script>
solves the comma problem in 1,234.56 but now there is a space after the period (i.e., before 5). I am not sure how the regex above works. can someone help?
Change the pattern to
/^(?:[0-9]+(?:,[0-9]{3})*(?:\.[0-9]*)*|\.[0-9]+)/
to allow 12,345.6 to be treated as a number, while 12, 345 is a list of two numbers. In the original pattern, the \{\.\} requires a literal {.} (braces included), not just a decimal.

Parsec does not recognize block comments

I have a problem with Parsec recognizing comments when parsing mustache templates.
The various mustache tags all start with {{ include the block comment ({{!comment}}).
I have set commentStart and commentEnd to {{! and }} in my TokenParser.
Whenever I add comments to a template, Parsec complains that the comment is unexpected.
It expects a mustache variable instead, since that is the only token that matches {{.
When does Parsec remove comments? I thought it would happen before the source hits my parser?
Parsec doesn't remove comments. In a TokenParser, comments are subsumed under white space, so
whiteSpace tokenParser
skips comments and ordinary white space (blanks, tabs, newlines, ...).
Usually, you use lexeme parser to skip all white space following a lexeme, then you only need one initial white-space-skipping for the top-level parser to skip any leading white space in the source, afterward, all white space (including comments) is handled automatically (by the TokenParser that makeTokenParser creates).
If you don't use lexeme and handle white space manually, you must take care of tokens/lexemes that are a prefix of the comment delimiter. If you try the prefix first, that will succeed, but only consume part of the comment delimiter, in this case leaving the '!' for the variable parser, which then fails.

How to write special characters like new line, and format output of haddock

I would like to format my haddock documentation as I do with javadoc, something like inserting html or any other markup that let me get a cleaner output without uncluding any javascript or CSS... Specially, I would like to know how to insert a line break in the documentation.
thanks!
Haddock is designed to work with multiple output formats, including LaTeX, so it uses its own markup format instead of something like HTML.
I don't think you can insert just a line break, but you can start a new paragraph by leaving a blank line, e.g.
-- | First paragraph.
--
-- Second paragraph.

help me create a vim snippet (snipmate)

Let's say I have the following snippet:
snippet divt
<div id="${1:div_id}">
${2:'some text'}
</div>
So when I type divt and hit tab twice "'some text'" should be selected, and when I hit tab once more I would like "some text" to be selected (witoutht single quotes). How can I do it?
Edit 1: Thanks for your answers. Probably this example makes more sense:
snippet divt
<div ${1:id="${2:div_id}"}>
</div>
Sometimes I want a div without an id, so i need to be able to delete the id="div_id" altogether. Sometimes i'd like to have an id, so that i can change div_id part only.
I am currently on a promoting trip for UltiSnips which I am maintaning. The snippet that does precisely that looks like this for UltiSnips:
snippet divt "div" b
<div ${1:id="${2:div_id}"}>
</div>
endsnippet
UltiSnips also comes with a converter script for snipMate snippets, so switching should be painless.
SnipMate unfortunately doesn't support nested placeholders but, as per #Benoit's advice, you could use another snippet while editing the second placeholder. Be sure to bring a spinning top with you, though.
I'm not sure what you want to achieve with some text vs 'some text' — both being treated exactly the same way in this context by every html parser on earth — but I would achieve that with a simple
snippet div
<div id="${1:div_id}">
${2}
</div>
and simply typing either
some text
or
'
which would be expanded to (| is the caret)
'|'
thanks to delimitMate or any other similar plugin then
'some text'
Or maybe use surround to change
some text|
into
'some text'
by typing
<Esc>v2bS'
With Surround you can also start with
some text
select it with
v2e
or something similar and type
S'
to add the quotes then select the line with
V
and type
S<div id="div_id">
to obtain
<div id="div_id">
'some text'
</div>
or do it the other way or... someone has to write a blog post with ALL the possible ways to achieve a given task in Vim.

Resources