org-mode icon indicating copy to clipboard operation
org-mode copied to clipboard

Bold and italics can be nested in each other.

Open gitonthescene opened this issue 3 years ago • 3 comments

This is not critical for me, but I thought I'd offer a heads up that the org-element.el parser does allow nesting of bold and italics text.

The GitHub org parser doesn't recognize it, but this is how emacs parses that file:

(org-data nil
	  (section
	   (:begin 1 :end 480 :contents-begin 1 :contents-end 480 :post-blank 0 :post-affiliated 1 :parent #0)
	   (paragraph
	    (:begin 1 :end 480 :contents-begin 1 :contents-end 480 :post-blank 0 :post-affiliated 1 :parent #1)
	    #("Let's try " 0 10
	      (:parent #2))
	    (bold
	     (:begin 11 :end 21 :contents-begin 12 :contents-end 20 :post-blank 0 :parent #2)
	     (italic
	      (:begin 12 :end 20 :contents-begin 13 :contents-end 19 :post-blank 0 :parent #3)
	      #("combos" 0 6
		(:parent #4))))
	    #("\nLet's try " 0 11
	      (:parent #2))
	    (bold
	     (:begin 32 :end 52 :contents-begin 33 :contents-end 51 :post-blank 0 :parent #2)
	     #("bold " 0 5
	       (:parent #3))
	     (italic
	      (:begin 38 :end 47 :contents-begin 39 :contents-end 45 :post-blank 1 :parent #3)
	      #("combos" 0 6
		(:parent #4)))
	     #("bold" 0 4
	       (:parent #3)))
	    #("\nLet's try " 0 11
	      (:parent #2))
	    (italic
	     (:begin 63 :end 73 :contents-begin 64 :contents-end 72 :post-blank 0 :parent #2)
	     (bold
	      (:begin 64 :end 72 :contents-begin 65 :contents-end 71 :post-blank 0 :parent #3)
	      #("combos" 0 6
		(:parent #4))))
	    #("\nLet's try " 0 11
	      (:parent #2))
	    (italic
	     (:begin 84 :end 104 :contents-begin 85 :contents-end 103 :post-blank 0 :parent #2)
	     #("bold " 0 5
	       (:parent #3))
	     (bold
	      (:begin 90 :end 99 :contents-begin 91 :contents-end 97 :post-blank 1 :parent #3)
	      #("combos" 0 6
		(:parent #4)))
	     #("bold" 0 4
	       (:parent #3)))
	    #("\nLet's try " 0 11
	      (:parent #2))
	    (bold
	     (:begin 115 :end 143 :contents-begin 116 :contents-end 142 :post-blank 0 :parent #2)
	     (italic
	      (:begin 116 :end 142 :contents-begin 117 :contents-end 141 :post-blank 0 :parent #3)
	      #("italics " 0 8
		(:parent #4))
	      (strike-through
	       (:begin 125 :end 134 :contents-begin 126 :contents-end 132 :post-blank 1 :parent #4)
	       #("combos" 0 6
		 (:parent #5)))
	      #("italics" 0 7
		(:parent #4))))
	    #("\nLet's try " 0 11
	      (:parent #2))
	    (bold
	     (:begin 154 :end 192 :contents-begin 155 :contents-end 191 :post-blank 0 :parent #2)
	     #("bold " 0 5
	       (:parent #3))
	     (italic
	      (:begin 160 :end 187 :contents-begin 161 :contents-end 185 :post-blank 1 :parent #3)
	      #("italics " 0 8
		(:parent #4))
	      (strike-through
	       (:begin 169 :end 178 :contents-begin 170 :contents-end 176 :post-blank 1 :parent #4)
	       #("combos" 0 6
		 (:parent #5)))
	      #("italics" 0 7
		(:parent #4)))
	     #("bold" 0 4
	       (:parent #3)))
	    #("\nLet's try " 0 11
	      (:parent #2))
	    (bold
	     (:begin 203 :end 231 :contents-begin 204 :contents-end 230 :post-blank 0 :parent #2)
	     (italic
	      (:begin 204 :end 230 :contents-begin 205 :contents-end 229 :post-blank 0 :parent #3)
	      #("italics " 0 8
		(:parent #4))
	      (underline
	       (:begin 213 :end 222 :contents-begin 214 :contents-end 220 :post-blank 1 :parent #4)
	       #("combos" 0 6
		 (:parent #5)))
	      #("italics" 0 7
		(:parent #4))))
	    #("\nLet's try " 0 11
	      (:parent #2))
	    (bold
	     (:begin 242 :end 280 :contents-begin 243 :contents-end 279 :post-blank 0 :parent #2)
	     #("bold " 0 5
	       (:parent #3))
	     (italic
	      (:begin 248 :end 275 :contents-begin 249 :contents-end 273 :post-blank 1 :parent #3)
	      #("italics " 0 8
		(:parent #4))
	      (underline
	       (:begin 257 :end 266 :contents-begin 258 :contents-end 264 :post-blank 1 :parent #4)
	       #("combos" 0 6
		 (:parent #5)))
	      #("italics" 0 7
		(:parent #4)))
	     #("bold" 0 4
	       (:parent #3)))
	    #("\nLet's try " 0 11
	      (:parent #2))
	    (bold
	     (:begin 291 :end 301 :contents-begin 292 :contents-end 300 :post-blank 0 :parent #2)
	     (strike-through
	      (:begin 292 :end 300 :contents-begin 293 :contents-end 299 :post-blank 0 :parent #3)
	      #("combos" 0 6
		(:parent #4))))
	    #("\nLet's try " 0 11
	      (:parent #2))
	    (bold
	     (:begin 312 :end 332 :contents-begin 313 :contents-end 331 :post-blank 0 :parent #2)
	     #("bold " 0 5
	       (:parent #3))
	     (strike-through
	      (:begin 318 :end 327 :contents-begin 319 :contents-end 325 :post-blank 1 :parent #3)
	      #("combos" 0 6
		(:parent #4)))
	     #("bold" 0 4
	       (:parent #3)))
	    #("\nLet's try " 0 11
	      (:parent #2))
	    (bold
	     (:begin 343 :end 353 :contents-begin 344 :contents-end 352 :post-blank 0 :parent #2)
	     (underline
	      (:begin 344 :end 352 :contents-begin 345 :contents-end 351 :post-blank 0 :parent #3)
	      #("combos" 0 6
		(:parent #4))))
	    #("\nLet's try " 0 11
	      (:parent #2))
	    (bold
	     (:begin 364 :end 384 :contents-begin 365 :contents-end 383 :post-blank 0 :parent #2)
	     #("bold " 0 5
	       (:parent #3))
	     (underline
	      (:begin 370 :end 379 :contents-begin 371 :contents-end 377 :post-blank 1 :parent #3)
	      #("combos" 0 6
		(:parent #4)))
	     #("bold" 0 4
	       (:parent #3)))
	    #("\nLet's try " 0 11
	      (:parent #2))
	    (bold
	     (:begin 395 :end 427 :contents-begin 396 :contents-end 426 :post-blank 0 :parent #2)
	     (underline
	      (:begin 396 :end 426 :contents-begin 397 :contents-end 425 :post-blank 0 :parent #3)
	      #("underline " 0 10
		(:parent #4))
	      (italic
	       (:begin 407 :end 416 :contents-begin 408 :contents-end 414 :post-blank 1 :parent #4)
	       #("combos" 0 6
		 (:parent #5)))
	      #("underline" 0 9
		(:parent #4))))
	    #("\nLet's try " 0 11
	      (:parent #2))
	    (bold
	     (:begin 438 :end 480 :contents-begin 439 :contents-end 479 :post-blank 0 :parent #2)
	     #("bold " 0 5
	       (:parent #3))
	     (underline
	      (:begin 444 :end 475 :contents-begin 445 :contents-end 473 :post-blank 1 :parent #3)
	      #("underline " 0 10
		(:parent #4))
	      (italic
	       (:begin 455 :end 464 :contents-begin 456 :contents-end 462 :post-blank 1 :parent #4)
	       #("combos" 0 6
		 (:parent #5)))
	      #("underline" 0 9
		(:parent #4)))
	     #("bold" 0 4
	       (:parent #3))))))

Somewhat surprisingly, though, on my Emacs the nesting isn't rendered for all the combinations. Compare the first two lines relative to the AST above.

Screen Shot 2021-11-11 at 7 02 42 PM

Interestingly, pandoc does a better job of it than emacs does. I believe pandoc is also written in Haskell, FWIW.

Again, this isn't critical, so feel free to close this issue.

Regards

P.S. Full disclosure: this is also a bit of an ad for my org-mode-samples. Hopefully this was more interesting than annoying. :D

gitonthescene avatar Nov 11 '21 10:11 gitonthescene

Interestingly pandoc gets *happy *dog* different than emacs.

(org-data nil
	  (section
	   (:begin 1 :end 14 :contents-begin 1 :contents-end 14 :post-blank 0 :post-affiliated 1 :parent #0)
	   (paragraph
	    (:begin 1 :end 14 :contents-begin 1 :contents-end 14 :post-blank 0 :post-affiliated 1 :parent #1)
	    (bold
	     (:begin 1 :end 13 :contents-begin 2 :contents-end 12 :post-blank 0 :parent #2)
	     #("happy *dog" 0 10
	       (:parent #3)))
	    #("\n" 0 1
	      (:parent #2)))))

I'm working on a PEG parser and I can get the same results as pandoc, but I am not sure how to get what emacs does. I also think it's fair to declare org-element.el wrong.

Here's my sample grammar, FWIW. You can ignore that the start and end of the type are actually the same.

line = linepart* '\n'
linepart = paren / s / z
s = '*'
e = '*'
paren = s n* e
n = paren / (!e z)
z = ~"[^\n\r]"

gitonthescene avatar Nov 12 '21 01:11 gitonthescene

I was always under the impression that Org didn't support nested markup like this. I wonder what the docs say these days...

fosskers avatar Dec 08 '21 22:12 fosskers

The whole state of the docs is a little off-putting. One of my side goals for collecting samples was to shine a brighter light on what’s actually going on.

gitonthescene avatar Dec 09 '21 03:12 gitonthescene