Skip to content

Commit d23df40

Browse files
committed
Fixed how prefix addition is handled for links
1 parent 5c89af0 commit d23df40

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

service/src/main/java/skills/services/ParagraphValidator.groovy

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,9 +723,13 @@ class ParagraphValidator {
723723
invalidate()
724724

725725
if (shouldAddPrefix(node)) {
726-
Paragraph paragraph = new Paragraph()
727-
paragraph.prependChild(new Text(request.prefix))
728-
node.insertBefore(paragraph)
726+
if (node instanceof Link) {
727+
addPrefixIfNeeded (node)
728+
} else {
729+
Paragraph paragraph = new Paragraph()
730+
paragraph.prependChild(new Text(request.prefix))
731+
node.insertBefore(paragraph)
732+
}
729733
}
730734
}
731735
return false
@@ -741,6 +745,8 @@ class ParagraphValidator {
741745
String currentHtml = htmlBlock.getLiteral()
742746
String newHtml = request.prefix + (currentHtml ?: "")
743747
customReplacements.put(markdownRenderer.render(previousNode), newHtml)
748+
} else if (validRes.closestNode instanceof BulletList) {
749+
addPrefixIfNeeded(node)
744750
} else {
745751
addPrefixIfNeeded(validRes)
746752
}

service/src/test/java/skills/services/InsertPrefixBasedOnCustomValidatorSpec.groovy

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,45 @@ noe more
226226
> * three
227227
> * four\n"""
228228

229+
validator.addPrefixToInvalidParagraphs("""(A) ok
230+
* item
231+
* item
232+
233+
<span>some text</span>
234+
""", prefix).newDescription == """(A) ok
235+
236+
* item
237+
* item
238+
239+
(A) <span>some text</span>
240+
"""
241+
242+
validator.addPrefixToInvalidParagraphs("""(A) ok
243+
* item
244+
* <span>item</span>
245+
246+
<span>some text</span>
247+
""", prefix).newDescription == """(A) ok
248+
249+
* item
250+
* <span>item</span>
251+
252+
(A) <span>some text</span>
253+
"""
254+
255+
validator.addPrefixToInvalidParagraphs("""(A) ok
256+
* item
257+
* <span>item</span>
258+
259+
[some text](https://some.url.com)
260+
""", prefix).newDescription == """(A) ok
261+
262+
* item
263+
* <span>item</span>
264+
265+
[(A) some text](https://some.url.com)
266+
"""
267+
229268
}
230269

231270
def "support markdown tables"() {
@@ -693,6 +732,7 @@ ___
693732

694733
then:
695734
validator.addPrefixToInvalidParagraphs("${url}", prefix).newDescription == "(A) ${url}\n"
735+
validator.addPrefixToInvalidParagraphs("[some text](${url})", prefix).newDescription == "[(A) some text](${url})\n"
696736
}
697737

698738
def "support html paragraphs" () {

0 commit comments

Comments
 (0)