@@ -500,6 +500,26 @@ private Table parseTable(final Path enclosingDocument, final Reader reader,
500500 while (!Objects .equals (token , next = reader .skipCommentsAndEmptyLines ()) && next != null ) {
501501 next = next .strip ();
502502 final var cells = new ArrayList <Element >();
503+ if (!next .startsWith ("|" ) && !rows .isEmpty () && !rows .get (rows .size () - 1 ).isEmpty ()) {
504+ final var lastRow = rows .get (rows .size () - 1 );
505+ final var line = cellParser .size () > lastRow .size () - 1
506+ ? cellParser .get (lastRow .size () - 1 ).apply (List .of (next ))
507+ : new Text (List .of (), next , Map .of ());
508+ final var last = lastRow .get (lastRow .size () - 1 );
509+ final Element replacement ;
510+ if (last instanceof Text lt && line instanceof Text le ) {
511+ replacement = mergeTexts (List .of (lt , le ));
512+ } else if (last instanceof Paragraph lt && line instanceof Paragraph le ) {
513+ replacement = new Paragraph (Stream .concat (lt .children ().stream (), le .children ().stream ()).toList (), lt .options ());
514+ } else if (last instanceof Paragraph lp ) {
515+ replacement = new Paragraph (Stream .concat (lp .children ().stream (), Stream .of (line )).toList (), lp .options ());
516+ } else {
517+ replacement = unwrapElementIfPossible (new Paragraph (List .of (last , line ), Map .of ("nowrap" , "true" )));
518+ }
519+ lastRow .set (lastRow .size () - 1 , replacement );
520+ continue ;
521+ }
522+
503523 if (next .indexOf ("|" , 2 ) > 0 ) { // single line row
504524 int cellIdx = 0 ;
505525 int last = 1 ; // line starts with '|'
@@ -854,13 +874,19 @@ private List<Element> parseLine(final Path enclosingDocument, final Reader reade
854874 backward = -1 ;
855875 }
856876
877+ var offset = 0 ;
857878 if (backward >= 0 && backward < i ) { // start by assuming it a link then fallback on a macro
858- final var optionsPrefix = line .substring (backward , i );
879+ var optionsPrefix = line .substring (backward , i );
859880 var options = parseOptions (line .substring (i + 1 , end ).strip ());
860881 if (start < backward ) {
861882 flushText (elements , line .substring (start , backward ));
862883 }
863884
885+ if (optionsPrefix .startsWith ("__" ) && line .substring (end ).startsWith ("]__" )) {
886+ optionsPrefix = optionsPrefix .substring (2 );
887+ offset = 2 ;
888+ }
889+
864890 final int macroMarker = optionsPrefix .indexOf (":" );
865891 if (macroMarker > 0 && !isLink (optionsPrefix )) {
866892 final boolean inlined = optionsPrefix .length () <= macroMarker + 1 || optionsPrefix .charAt (macroMarker + 1 ) != ':' ;
@@ -931,8 +957,8 @@ enclosingDocument, new Reader(List.of(label)),
931957 linkLabel ,
932958 removeEmptyKey (options )));
933959 }
934- i = end ;
935- start = end + 1 ;
960+ i = end + offset ;
961+ start = i + 1 ;
936962 continue ;
937963 }
938964
@@ -1485,17 +1511,25 @@ private void flushOption(final String defaultKey,
14851511 final var keyValue = key .toString ();
14861512 if (value .isEmpty ()) {
14871513 if (keyValue .startsWith ("." )) {
1488- collector .put ("role" , keyValue .substring (1 ));
1514+ collector .put ("role" , keyValue .substring (1 ). replace ( '.' , ' ' ) );
14891515 } else if (keyValue .startsWith ("#" )) {
14901516 collector .put ("id" , keyValue .substring (1 ));
14911517 } else {
1492- collector .put (defaultKey , keyValue );
1518+ collector .put (defaultKey , dropLegacyPassthroughMarkers ( keyValue ) );
14931519 }
14941520 } else {
1495- collector .put (keyValue , value .toString ());
1521+ collector .put (
1522+ keyValue ,
1523+ dropLegacyPassthroughMarkers (value .toString ()));
14961524 }
14971525 }
14981526
1527+ private static String dropLegacyPassthroughMarkers (final String v ) {
1528+ return v .length () > 3 && v .startsWith ("$$" ) && v .endsWith ("$$" ) ?
1529+ v .substring (2 , v .length () - 2 ) :
1530+ v ;
1531+ }
1532+
14991533 private Element parseSection (final Path enclosingDocument , final Reader reader , final Map <String , String > options ,
15001534 final ContentResolver resolver , final Map <String , String > currentAttributes ) {
15011535 final var title = reader .skipCommentsAndEmptyLines ();
0 commit comments