Comments (5)
Workaround:
const snarkdownEnhanced = (md: string) => {
const htmls = md
.split(/(?:\r?\n){2,}/)
.map(l =>
[' ', '\t', '#', '-', '*'].some(ch => l.startsWith(ch))
? snarkdown(l)
: `<p>${snarkdown(l)}</p>`,
)
return htmls.join('\n\n')
}
Note that it will fail for fenced code blocks and probably other edge cases.
from snarkdown.
Workaround:
const snarkdownEnhanced = (md: string) => { const htmls = md .split(/(?:\r?\n){2,}/) .map(l => [' ', '\t', '#', '-', '*'].some(ch => l.startsWith(ch)) ? snarkdown(l) : `<p>${snarkdown(l)}</p>`, ) return htmls.join('\n\n') }Note that it will fail for fenced code blocks and probably other edge cases.
This was what I needed. Appreciate it.
I understand that the scope of snarkdown is minimal, but personally I just can't imagine ever using a markdown file to make something only one line long. imo Enhanced should be default. But what do I know.
Thanks everyone.
from snarkdown.
from snarkdown.
from snarkdown.
Heres a patch (still a bit of a hack) that I put together to wrap all loose text in <p>
s. Unlike the solution above, it seems to work fine with fenced code blocks.
export default function(md) {
// Run snarkdown
let out = parse(md);
// Add opening <p>
if (!out.trim().startsWith('<')) {
out = `<p>${out}`;
}
out = out
// Replace e.g. "</h5>The..." with "</h5><p>The..."
.replace(/(<(\/(h(\d))|em|strong|s|div|pre)>)([\s\r\n]){0,}([\w\d])/g, match => {
const chars = [
match.slice(0, match.length - 1),
match.slice(match.length - 1)
];
return `${chars[0]}<p>${chars[1]}`
})
// Replace <br> with </p><p>
.replace(/<br \/>/g, '</p><p>')
// Ensure paragraphs before h-tags end with </p>
.replace(/([\w\d.:;])([\r\n]){1,}(<((h(\d))|em|strong|s|div|pre)>)/g, (match, paraChars, space, followingEl) => {
return `${paraChars || ''}</p>${space || ''}${followingEl || ''}`
})
// Div fix
.replace(/<\/p><p><div/g, '</p><div')
.replace(/<\/div><\/p>/g, '</div>')
// Strong, em fix
.replace(/<strong><p>/g, '<strong>')
.replace(/<em><p>/g, '<em>')
// Pre fix
.replace(/<p><pre/g, '<pre')
.replace(/<\/pre><\/p>/g, '</pre>')
// Ul fix
.replace(/<p><ul/g, '<ul')
.replace(/<\/ul><\/p>/g, '</ul>')
// Ol fix
.replace(/<p><ol/g, '<ol')
.replace(/<\/ol><\/p>/g, '</ol>')
// Add closing </p>
if (!out.trim().endsWith('>')) {
out = `${out}</p>`;
}
return out;
}
from snarkdown.
Related Issues (20)
- Strikethrough not working HOT 3
- HR not working after PRE
- Nested lists not working HOT 3
- unexpected link generated HOT 1
- feature request: fenced divs
- Add id to headings HOT 1
- Issue with ruler after <h3>
- The output for nested italic and bold is incorrect. HOT 3
- Exposiing the parser API
- Add usage example with PrismJS HOT 1
- pre+code tag instead of just pre HOT 1
- module not defined HOT 1
- Type declarations missing in npm package HOT 2
- v2.0 breaking changes HOT 1
- Angle-bracket link/url syntax not supported
- Date formatting support
- Unexpected parsing with single characters such as * HOT 1
- Markdown code not formatting correctly on uptime website HOT 3
- export declarations may only appear at top level of a module
- in inline html, attribute values are incorrectly parsed as markdown HOT 4
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.
from snarkdown.