2022-12-05 - T383838md2gemini eats newlines in code blocks in item lists
Well, I was going to get a good night's sleep, but I really wanted to publish my stuff. And so TIL there's a bug in the handling of list items in the python T383838md2gemini. I spent at least three hours trying really dumb hacks of applying T383838sed expressions, reformatting my markdown, and trying different T383838pandoc options... I went reading about how some others have moved from various markdown converters until they went off and created their own... you know who you are, and you've done impressive things, but it doesn't do the things I like about T383838md2gemini. No other converters were as close to what I wanted as T383838md2gemini is. So I cloned the project off github, made liberal use of T383838import pdb and T383838pdb.set_trace() and I found the spot where things go poorly.
T282828
Tff7b72def Td2a8fflist_itemTb4b4b4(Tff7b72selfTb4b4b4, Te6edf3textTb4b4b4, Te6edf3levelTb4b4b4)Tb4b4b4:
Te6edf3items Tff7b72= Tb4b4b4[Te6edf3itemTff7b72.Td2a8ffstripTb4b4b4(Tb4b4b4) Tff7b72for Te6edf3item Tff7b72in Te6edf3textTff7b72.Td2a8ffsplitlinesTb4b4b4(Tb4b4b4)Tb4b4b4]
Te6edf3text Tff7b72= Te6edf3functoolsTff7b72.Td2a8ffreduceTb4b4b4(Tff7b72lambda Te6edf3xTb4b4b4, Te6edf3yTb4b4b4: Te6edf3x Tff7b72+ Ta5d6ff"Ta5d6ff Ta5d6ff" Tff7b72+ Te6edf3yTb4b4b4, Te6edf3itemsTb4b4b4)
Tff7b72return Te6edf3text Tff7b72+ Te6edf3NEWLINE
This is a decent chunk of code and it's pretty quick, but it naively rips out all the newlines from the list item that's being parsed. In the troubled article I had a list of steps that included pre-formatted or code blocks of commands to execute. This stanza will cheerfully squash the entire code block into one line and cause me to stare tearfully at my monitor and consider different career paths.
I wrote some really quick code as a hack to just get it working so I can publish. I'm going to shamelessly post it here, but I'll definitely need to clean it up if anyone else is going to use it.
T282828
Tff7b72def Td2a8fflist_itemTb4b4b4(Tff7b72selfTb4b4b4, Te6edf3textTb4b4b4, Te6edf3levelTb4b4b4)Tb4b4b4:
Te6edf3new_text Tff7b72= Ta5d6ff'Ta5d6ff'
Te6edf3in_fence Tff7b72= Tff7b72False
Te6edf3text Tff7b72= Te6edf3textTff7b72.Td2a8ffreplaceTb4b4b4(Te6edf3PARAGRAPH_DELIMTb4b4b4, Te6edf3PARAGRAPH_DELIMTff7b72+Ta5d6ff'Tffea00\rTffea00\nTa5d6ff'Tb4b4b4)
Tff7b72for Te6edf3item Tff7b72in Te6edf3textTff7b72.Td2a8ffsplitlinesTb4b4b4(Tb4b4b4)Tb4b4b4:
Te6edf3was_in_fence Tff7b72= Te6edf3in_fence
Te6edf3in_fence Tff7b72= Tff7b72not Te6edf3in_fence Tff7b72if Te6edf3itemTff7b72.Td2a8fflstripTb4b4b4(Tb4b4b4)Tff7b72.Td2a8ffstartswithTb4b4b4(Ta5d6ff'Ta5d6ff```Ta5d6ff'Tb4b4b4) Tff7b72else Te6edf3in_fence
Tff7b72if Te6edf3in_fenceTb4b4b4:
Te6edf3new_text Tff7b72+Tff7b72= Te6edf3LINEBREAK Tff7b72+ Te6edf3item
Tff7b72elseTb4b4b4:
Tff7b72if Te6edf3was_in_fenceTb4b4b4:
Te6edf3new_text Tff7b72+Tff7b72= Te6edf3LINEBREAK Tff7b72+ Te6edf3item Tff7b72+ Te6edf3LINEBREAK Tff7b72+ Te6edf3LINEBREAK
Tff7b72elseTb4b4b4:
Te6edf3new_text Tff7b72+Tff7b72= Ta5d6ff'Ta5d6ff Ta5d6ff' Tff7b72+ Te6edf3item
Tff7b72return Te6edf3new_text Tff7b72+ Te6edf3NEWLINE
Tags: python, index
Tags
Navigation