-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix parsing issues with Windows end of line characters (#9)
- Loading branch information
Showing
10 changed files
with
275 additions
and
96 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
markdown/src/main/kotlin/com/appmattus/markdown/processing/DocumentExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import com.vladsch.flexmark.util.Utils | ||
import com.vladsch.flexmark.util.ast.Document | ||
import com.vladsch.flexmark.util.sequence.BasedSequence | ||
|
||
@Suppress("ReturnCount") | ||
fun Document.getLineNumberFixed(offset: Int): Int { | ||
val lineSegments = contentLines | ||
if (lineSegments === BasedSequence.EMPTY_LIST) { | ||
val preText = chars.baseSubSequence(0, Utils.maxLimit(offset, chars.length)) | ||
if (preText.isEmpty()) return 0 | ||
var lineNumber = 0 | ||
var nextLineEnd = preText.endOfLineAnyEOL(0) | ||
val length = preText.length | ||
while (nextLineEnd < length) { | ||
lineNumber++ | ||
nextLineEnd = preText.endOfLineAnyEOL(nextLineEnd + preText.eolLength(nextLineEnd)) | ||
} | ||
return lineNumber | ||
} else { | ||
val iMax = lineSegments.size | ||
for (i in 0 until iMax) { | ||
if (offset < lineSegments[i].endOffset) { | ||
return i | ||
} | ||
} | ||
return iMax | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
markdown/src/main/kotlin/com/appmattus/markdown/rules/extentions/NodeExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
package com.appmattus.markdown.rules.extentions | ||
|
||
import com.vladsch.flexmark.util.ast.Node | ||
import getLineNumberFixed | ||
|
||
fun Node.indent(): Int = document.chars.getColumnAtIndex(startOffset) | ||
|
||
val Node.startLineNumberFixed: Int | ||
get() { | ||
return document!!.getLineNumberFixed(chars.startOffset) | ||
} | ||
|
||
val Node.endLineNumberFixed: Int | ||
get() { | ||
val endOffset = chars.endOffset | ||
return document!!.getLineNumberFixed(if (endOffset > 0) endOffset - 1 else endOffset) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.