Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Muse: do not allow newlines after opening and before closing "*" #5

Closed
link2xt opened this issue Oct 13, 2019 · 14 comments
Closed

Muse: do not allow newlines after opening and before closing "*" #5

link2xt opened this issue Oct 13, 2019 · 14 comments
Assignees

Comments

@link2xt
Copy link
Contributor

link2xt commented Oct 13, 2019

This should not be highlighted as emphasized:

*
foo bar*

This is unclosed emphasis:

*foo bar
*
@Alhadis
Copy link
Owner

Alhadis commented Oct 14, 2019

This is actually impossible to fix due to the limitations of the TextMate grammar system. It processes documents one line at a time, which means something like this:

foo *bar
*

is impossible to differentiate from this:

foo *bar
baz*

I could prevent a lone * from starting an emphasised text run, however:

/^\*$/

@Alhadis Alhadis self-assigned this Oct 14, 2019
@link2xt
Copy link
Contributor Author

link2xt commented Oct 14, 2019

@Alhadis
Copy link
Owner

Alhadis commented Oct 14, 2019

Yes, that's because Atom recently changed their highlighting-engine to support newlines. However, other TextMate-grammar implementations don't support this (notably GitHub's).

You can see for yourself:

@link2xt
Copy link
Contributor Author

link2xt commented Oct 14, 2019

You can see for yourself:
...

First example works correctly, the second I just fixed:
https://github.com/link2xt/atom-muse/commit/0a728c9e918f0ba90406cf5c2c1d635d27e2cc98

Now both examples work correctly on https://github-lightshow.herokuapp.com/

@Alhadis
Copy link
Owner

Alhadis commented Oct 14, 2019

What about this?

*foo bar
* baz

Lightshow is tokenising it as

<pre class="code"><span class="pl-mi">*foo bar</span>
<span class="pl-mi">* baz</span>
</pre>

... but Pandoc gives me:

<p>*foo bar</p>
<h1 id="baz">baz</h1>

@link2xt
Copy link
Contributor Author

link2xt commented Oct 14, 2019

This markup is invalid because * is not closed, so I am not sure here. Pandoc also gives this:

$ pandoc -f muse -t native
*foo bar
----
baz*
[Para [Emph [Str "foo",Space,Str "bar",SoftBreak,Str "----",SoftBreak,Str "baz"]]]

Generally speaking, any block markup should break paragraphs, and it is better to parse it as

[Para [Str "*foo",Space,Str "bar"]
,HorizontalRule
,Para [Str "baz*"]]

because otherwise we can't determine if the second line is a block or not without parsing the third line. Pandoc implementation does backtracking which may be quite expensive in extreme cases, like lots of nested unclosed tags.

In muse.cson emphasis consumes more than it should because I do not parse paragraphs beforehand, it is a bug.

@link2xt
Copy link
Contributor Author

link2xt commented Oct 14, 2019

Alternatively, it can be treated as a part of inline markup, even if there is no closing *. In other workds, unclosed inline markup is undefined behavior.

@Alhadis
Copy link
Owner

Alhadis commented Oct 14, 2019

How should this be treated?

Foo **bold**bar baz qux** qul

The Text::Amuse wiki says:

The opening one must be preceded by something which is not an alphanumerical character (or at the beginning of the line) and followed by something which is not a space.

This means that the code above should be rendered like this:

<p>Foo *<em>boldbar baz qux</em>* qul</p>

But, wouldn't it be more natural to render it like this...?

<p>Foo <strong><em>boldbar baz qux</em></strong> qul</p>

@link2xt
Copy link
Contributor Author

link2xt commented Oct 14, 2019

I think it should be

<p>Foo <strong>bold**bar baz qux</strong> qul</p>

Text::Amuse produced this:

<p>
Foo <strong>bold**bar baz qux</strong> qul
</p>

@link2xt
Copy link
Contributor Author

link2xt commented Oct 14, 2019

Pandoc is fixed, now it produces

<p>Foo <strong>bold**bar baz qux</strong> qul</p>

@Alhadis
Copy link
Owner

Alhadis commented Oct 15, 2019

Is there a painless way to run an up-to-date Text::Amuse from command-line? muse-quick.pl is deprecated and installing Text::Amuse::Compile is proving to be a pain-in-the-arse due to this shitty MacBook's crippled build system (I don't know what the previous owner did to it, but anything relying on a C compiler is broken...).

All I need is the raw HTML output, I don't give a crap about EPUB or LaTeX, so there's a million CPAN dependencies I don't need which are probably adding to the installation grief.

@link2xt
Copy link
Contributor Author

link2xt commented Oct 15, 2019

You can use this script prepared for GitHub markup repository:
https://github.com/link2xt/markup/blob/muse/lib/github/commands/muse2html

@Alhadis
Copy link
Owner

Alhadis commented Oct 15, 2019

Lol, too late.

Thanks anyway though. 😅

@Alhadis
Copy link
Owner

Alhadis commented Oct 15, 2019

Okay, I think I've fixed the emphasis matching. Could I get you to update your branch locally and tell me if there's anything I've missed?

Bear in mind there's nothing we can do about this:

Foo *italic*unclosed italic

Which, given TextMate's limitations, is for all intents and purposes the same as:

Foo *italic*unclosed italic
bar* baz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants