Comments (1)
I came across this issue too today. Doesn't even require MD -> HTML -> MD conversion. The issue is simply in HTML -> MD.
Given the following html:
Line 1<br>
Line 2<br>
Line 3<br>
Showdown will produce the following markdown:`
Line 1<br>
Line 2<br>
Line 3<br>
Did some digging and realised that this is because the tagged release version of showdown 2.1.0 doesn't contain the makeMarkdown.break
subparser, or the case statement in the makeMarkdown.node
subparser that would call it - meaning that it goes to the default case in makeMarkdown.node
which simply outputs the tag + \n\n
.
I monkeypatched these in, and it mostly solves the problem. With the two changes mentioned above in the code the markdown output becomes:
Line 1
Line 2
Line 3
The issue now is the leading space appearing on the 2nd and 3rd lines. A little bit more investigation and I found line 400 in converter.js in the clean()
function
child.nodeValue = child.nodeValue.split('\n').join(' ');
Modifying this line to join('')
solved the problem, and removed the leading spaces, and seemed to cause no other issues (for me at least). But it did cause some tests to fail - it is possible that there could be textnodes across multiple lines that would need to be joined with a space.
My solution to this was to simply remove the space at the start of any line in the parse markdown that started with a single space. I don't think there would be any other occasions this would happen - it would only be following a linebreak.
Adding this on line 393 of converter.js
mdDoc.split(/\n/).map(function (line) {
// Remove the space the start of any line that only starts with one and only one space
return line.replace(/^\s{1}\S+/, '');
}).join('\n');
This feels a bit of a hack, but it works. All the tests pass, and adding a testcase for the starting html and expected markdown passes too. Maybe there's a more elegant solution?
Is there any way to get <br>
handling published? It would be really helpful.
I can't quite work out the status of showdown - as I mentioned some of this 'fix' is already in 'develop' and 'master' branch. It doesn't seem liek there's a lot of active developemnt. Is there a new release planned at any point? We're actively using this in our app, and would love for stuff like this to work out of the box, rather than having to include workarounds in our app code (or have the overhead of managing a fork). If there's anything I can do to help / contribute to the project then I'm happy to
Thanks a lot,
Chris
from showdown.
Related Issues (20)
- markdown from openAi streamed data gives weird results
- Showdown escaping HTML Chars but not constantly HOT 1
- Incorrect Regex in "Add default classes for each HTML element" Wiki Page
- superscript and subscript not working HOT 1
- Data Science ANnd Machine Learning
- Error in parsing hashtag at start of line
- Issues installing this package with React version >= 17 HOT 1
- Option `parseImgDimensions` is actually `true` by default despite doc, and also, when `false` still behaves as if `true` HOT 2
- URL not converting properly
- Links without protocol are threated as links, but behave as path
- Strikethroughs won't render. HOT 2
- showdownJS Domain expired HOT 1
- NPM installation browser support HOT 2
- [Suggestion] Markdown to array of objects
- Potential Security Issue
- Vulnerability Reporting
- Request for Security Contact HOT 1
- ghCodeBlocks set to false but keeps rendering <code> and <pre> tags
- Tables dont work in normal llm formats
- Yaml-like Metadata parser does not handle colons in entries; returns undefined HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
conversions from MD to HTML to MD
from showdown.