Skip to content

Commit c8d561d

Browse files
committed
Fixed generated image tags.
1 parent 002ac5e commit c8d561d

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

changelog.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Scala Markdown
22
==============
33

4+
[Scala Markdown 1.4](http://scalamd.fusesource.org/maven/1.4), December 22, 2010
5+
----
6+
7+
* Generated image tags were broken
8+
49
[Scala Markdown 1.3](http://scalamd.fusesource.org/maven/1.3), December 16, 2010
510
----
611

src/main/scala/md.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ object Markdown {
7979
"(?:" + htmlNameTokenExpr + "\\s*=\\s*\"[^\"]*\")|" +
8080
"(?:" + htmlNameTokenExpr + "\\s*=\\s*'[^']*')|" +
8181
"(?:" + htmlNameTokenExpr + "\\s*=\\s*[a-z0-9_:.\\-]+)" +
82-
")\\s*)*)>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE)
82+
")\\s*)*)/?>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE)
8383
// Headers
8484
val rH1 = Pattern.compile("^ {0,3}(\\S.*?)( *\\{#(.*?)\\})?\\n=+(?=\\n+|\\Z)", Pattern.MULTILINE)
8585
val rH2 = Pattern.compile("^ {0,3}(\\S.*?)( *\\{#(.*?)\\})?\\n-+(?=\\n+|\\Z)", Pattern.MULTILINE)
@@ -255,10 +255,11 @@ class MarkdownText(source: CharSequence) {
255255
* Encodes specially-treated characters inside the HTML tags.
256256
*/
257257
protected def encodeCharsInsideTags(text: StringEx) =
258-
text.replaceAll(rInsideTags, m =>
258+
text.replaceAll(rInsideTags, { m =>
259+
val tail = if( m.group(0).endsWith("/>") ) "/>" else ">"
259260
"<" + encodeUnsafeChars(new StringEx(m.group(1)))
260261
.replaceAll(rEscAmp, "&amp;")
261-
.toString + ">")
262+
.toString + tail})
262263

263264
// ## Processing methods
264265

src/test/resources/Images.html

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<p><img src="/path/to/img.jpg" alt="Alt text"/>
2+
<img src="/path/to/img.jpg" alt="Alt text" title="Optional title"/></p>

src/test/resources/Images.text

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
![Alt text](/path/to/img.jpg)
2+
![Alt text](/path/to/img.jpg "Optional title")

src/test/scala/test.scala

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ object MarkdownSpec extends Specification {
2020
val textFile = new File(this.getClass.getResource("/" + name + ".text").toURI)
2121
val htmlFile = new File(this.getClass.getResource("/" + name + ".html").toURI)
2222
val text = Markdown(FileUtils.readFileToString(textFile, "UTF-8")).trim
23+
// println("[%s]".format(text))
2324
val html = FileUtils.readFileToString(htmlFile, "UTF-8").trim
2425
val diffIndex = StringUtils.indexOfDifference(text, html)
2526
val diff = StringUtils.difference(text, html)
@@ -32,6 +33,9 @@ object MarkdownSpec extends Specification {
3233
def process = addToSusVerb("process")
3334

3435
"MarkdownProcessor" should process {
36+
"Images" in {
37+
"Images" must beFine
38+
}
3539
"TOC" in {
3640
"TOC" must beFine
3741
}

0 commit comments

Comments
 (0)