asciidoc-py / asciidoc-py2

Deprecated python2 implementation of AsciiDoc.py. See asciidoc-py/asciidoc-py for current work.
https://asciidoc.org/
GNU General Public License v2.0
466 stars 128 forks source link

Fix dashes after comment bug #105

Closed hedrok closed 7 years ago

hedrok commented 7 years ago

Fix #104

The bug was in asciidoc.conf: (\n-- )|( -- )|( --\n)= — 

So

Line 1
// comment
-- Line 2

is transformed to

Line 1
// comment -- Line 2

(because (\n is removed)) and "-- Line 2" vanishes.

So i replaced this line with (\n-- )=\n —  ( -- )|( --\n)= — 

I tried to add test, but I can't see where expected results are. As far as I can see, they are generated by ./testasciidoc.py update so I can't really see the point of these tests: if expected is generated by program that will be tested, we always get PASSED... Please help.

elextr commented 7 years ago

Hmm, yes, now I remember, thats a pecularity of the asciidoc tests, they are more for finding unintended effects of a change, so you generate the results first, make the change and check that only the thing you fixed changes, sort of backwards. Its a methodology thats more suited to when new features were being added than now in the maintenance phase.

hedrok commented 7 years ago

That makes sense. Ok, I've generated expected without my changes and ran tests after my changes. Two tests failed for all backends (I copied only one case for one backend):

1: Test cases
SOURCE: asciidoc: data/testcases.txt
FAILED: html4: data/testcases-html4.html
+++ data/testcases-html4.html
--- got
-<p><b>Exceptions</b><br>There are a number of  exceptions to the usual single backslash rule
-&#8201;&#8212;&#8201;mostly relating to URL macros that  have two syntaxes or quoting
+<p><b>Exceptions</b><br>There are a number of  exceptions to the usual single backslash rule&#8201;&#8212;&#8201;mostly relating to URL macros that  have two syntaxes or quoting

Which is kinda bad, because for

There are a number of  exceptions to the usual single backslash rule
-- mostly relating to URL macros that  have two syntaxes or quoting

we get end of line (normal space) AND thin space (& # 8201) after rule. On the other hand if there is space before "--" we will get same result, which is expected in my opinion...

What should I do? Should I try to fix "--" after comment without changing any other previous behaviour? Or is this ok?..

elextr commented 7 years ago

Its a peculiarity of the implementation I think, line comments are actually a form of macro that has no output. So the line comment does not include the terminating line end which is considered part of the text. This is the normal definition for macros and I doubt it could be changed without breaking lots.

So comments are replaced by blank lines in the output, ie nothing and the line end.

Normally blank lines are not meaningful but, if you use a comment somewhere that the blank line affects the output rendering, then that is what is expected from such a macro.

Effectively, don't put a comment where you can't afford whitespace to show.

Since the -- replacement has been done before the macro detection (see here) I don't think you can easily fix it, and I its so rare I doubt its worth the effort of trying.

hedrok commented 7 years ago

Ok, last try:

I just added replace for this specific case:

\n//.*\n-- =\n&#8201;&#8212;&#8201;

So I remove comment before "-- " at special characters stage.

This change is backward-compatible except in this specific case (all tests passed), and I can't see how this behaviour can be worse than loosing a line, even in rare cases :)

Sorry for disturbing you - this is really last try, I won't waste your time on this issue anymore.

elextr commented 7 years ago

Comments can be shown with the showcomment attribute, so this breaks that.

hedrok commented 7 years ago

Ok, sorry.