Skip to content

Commit

Permalink
Bug fix to NoSpaceInEmphasisRule to ignore code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmook committed Mar 13, 2019
1 parent 8cc60c8 commit 0124c1a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.appmattus.markdown.rules

import com.appmattus.markdown.processing.MarkdownDocument
import com.appmattus.markdown.dsl.RuleSetup
import com.appmattus.markdown.errors.ErrorReporter
import com.appmattus.markdown.processing.MarkdownDocument
import com.vladsch.flexmark.ast.Code
import com.vladsch.flexmark.ast.FencedCodeBlock
import com.vladsch.flexmark.ast.IndentedCodeBlock

/**
* # Spaces inside emphasis markers
Expand Down Expand Up @@ -46,7 +49,9 @@ class NoSpaceInEmphasisRule(

override fun visitDocument(document: MarkdownDocument, errorReporter: ErrorReporter) {

document.allText.forEach {
document.allText.filterNot {
it.parent is FencedCodeBlock || it.parent is IndentedCodeBlock || it.parent is Code
}.forEach {
if (it.chars.contains(startRegex) || it.chars.contains(endRegex)) {
errorReporter.reportError(it.startOffset, it.endOffset, description)
}
Expand Down
16 changes: 16 additions & 0 deletions markdown/src/test/resources/spaces_inside_emphasis_markers.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,19 @@ One-sided * broken emphasis* {NoSpaceInEmphasisRule}
Don't _flag on _words with underscores before them.

The same goes for words* with asterisks* after them.

```text
/*
*
* Ignore code blocks
*
*/
```

/**
*
* Ignore * code * blocks
*
*/

`/* Ignore * code * blocks */`

0 comments on commit 0124c1a

Please sign in to comment.