mirror of
https://github.com/Noratrieb/slides.git
synced 2026-03-15 05:16:03 +01:00
Correctly strip leading white-space from markdown
If the markdown contains something that is indented by more that the
`leadingTabs`/`leadingWs` then extra white space is incorrectly removed.
ie the following example:
```
<section data-markdown>
some text
indented text
more indented text
</section>
```
would result in the following markdown:
```
some text
indented text
more indented text
```
We can work around this problem by using a function to generate the
replace value.
This commit is contained in:
parent
b1a9842b2f
commit
ae652a8e4e
3 changed files with 4 additions and 4 deletions
|
|
@ -47,10 +47,10 @@ const Plugin = () => {
|
|||
leadingTabs = text.match( /^\n?(\t*)/ )[1].length;
|
||||
|
||||
if( leadingTabs > 0 ) {
|
||||
text = text.replace( new RegExp('\\n?\\t{' + leadingTabs + '}','g'), '\n' );
|
||||
text = text.replace( new RegExp('\\n?\\t{' + leadingTabs + '}(.*)','g'), function(m, p1) { return '\n' + p1 ; } );
|
||||
}
|
||||
else if( leadingWs > 1 ) {
|
||||
text = text.replace( new RegExp('\\n? {' + leadingWs + '}', 'g'), '\n' );
|
||||
text = text.replace( new RegExp('\\n? {' + leadingWs + '}(.*)', 'g'), function(m, p1) { return '\n' + p1 ; } );
|
||||
}
|
||||
|
||||
return text;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue