Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

CRLF line endings fix #25

Merged
merged 3 commits into from about 1 year ago

2 participants

ppetrov Hisateru Tanaka
ppetrov

Hi,
I recently had an issue converting markdown files explicitly saved in Windows Format CR+LF format.
This tiny fix seems to have fixed that problem ;).

I additionally added some unit tests based on QUnit.

Hisateru Tanaka
Owner

I've understood what a problem by your commit 0d43cb7 .
Thanks, and I will merge it in 2 days!

Hisateru Tanaka tanakahisateru merged commit f962e76 into from March 31, 2013
Hisateru Tanaka tanakahisateru closed this March 31, 2013
ppetrov petarov deleted the branch April 01, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
2  js-markdown-extra.js
@@ -287,7 +287,7 @@ Markdown_Parser.prototype.transform = function(text) {
287 287
 
288 288
     // Standardize line endings:
289 289
     //   DOS to Unix and Mac to Unix
290  
-    text = text.replace(/\r\n?/, "\n", text);
  290
+    text = text.replace(/\r\n?/g, "\n", text);
291 291
 
292 292
     // Make sure $text ends with a couple of newlines:
293 293
     text += "\n\n";
21  run-unit-tests.html
... ...
@@ -0,0 +1,21 @@
  1
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
  2
+                    "http://www.w3.org/TR/html4/loose.dtd">
  3
+<html>
  4
+<head>
  5
+    <meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
  6
+    <script src="js-markdown-extra.js"></script>
  7
+    <script src="http://code.jquery.com/qunit/qunit-1.11.0.js"></script>
  8
+    <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.11.0.css" type="text/css" media="screen" />
  9
+</head>
  10
+<body>
  11
+<h1 id="qunit-header">js-markdown-extra</h1>
  12
+<h2 id="qunit-banner"></h2>
  13
+<div id="qunit-testrunner-toolbar"></div>
  14
+<h2 id="qunit-userAgent"></h2>
  15
+<ol id="qunit-tests"></ol>
  16
+<div id="qunit-fixture">test markup, will be hidden</div>
  17
+
  18
+<script src="unit-tests/crlf.js"></script>
  19
+
  20
+</body>
  21
+</html>
52  unit-tests/crlf.js
... ...
@@ -0,0 +1,52 @@
  1
+module( "CRLF Unit tests" );
  2
+
  3
+// Used - http://www.howtocreate.co.uk/tutorials/jsexamples/syntax/prepareInline.html
  4
+var expected = '<h1>Syntax Cheatsheet<\/h1>\n\n<h2>PHRASE EMPHASIS<\/h2>\n\n<p><em>italic<\/em>   <strong>bold<\/strong>\n<em>italic<\/em>   <strong>bold<\/strong><\/p>\n\n<h1>Header 1<\/h1>\n\n<h2>Header 2<\/h2>\n\n<h1>Header 1<\/h1>\n\n<h2>Header 2<\/h2>\n\n<h6>Header 6<\/h6>\n';
  5
+
  6
+/* 
  7
+ * Test 01 - LF
  8
+ */
  9
+QUnit.test( "01 - LF", function() {
  10
+	
  11
+	var input =
  12
+		'Syntax Cheatsheet' + "\n" +
  13
+		'========================================' + "\n" +
  14
+		'PHRASE EMPHASIS' + "\n" +
  15
+		'---------------' + "\n" +
  16
+		'*italic*   **bold**' + "\n" +  
  17
+		'_italic_   __bold__' + "\n" +
  18
+		'Header 1' + "\n" +
  19
+		'========' + "\n" +
  20
+		'Header 2' + "\n" +
  21
+		'--------' + "\n" +
  22
+		'# Header 1 #' + "\n" +
  23
+		'## Header 2 ##' + "\n" +
  24
+		'###### Header 6' + "\n";	
  25
+	
  26
+	var result = Markdown(input);
  27
+	QUnit.assert.equal(result, expected);
  28
+});
  29
+
  30
+/* 
  31
+ * Test 02 - CRLF
  32
+ */
  33
+QUnit.test( "02 - CRLF", function() {
  34
+	
  35
+	var input =
  36
+		'Syntax Cheatsheet' + "\r\n" +
  37
+		'========================================' + "\r\n" +
  38
+		'PHRASE EMPHASIS' + "\r\n" +
  39
+		'---------------' + "\r\n" +
  40
+		'*italic*   **bold**' + "\r\n" +  
  41
+		'_italic_   __bold__' + "\r\n" +
  42
+		'Header 1' + "\r\n" +
  43
+		'========' + "\r\n" +
  44
+		'Header 2' + "\r\n" +
  45
+		'--------' + "\r\n" +
  46
+		'# Header 1 #' + "\r\n" +
  47
+		'## Header 2 ##' + "\r\n" +
  48
+		'###### Header 6' + "\r\n";	
  49
+	
  50
+	var result = Markdown(input);
  51
+	QUnit.assert.equal(result, expected);
  52
+});
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.