Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #10 from jamesramsay/para-breaks
Browse files Browse the repository at this point in the history
Para breaks
  • Loading branch information
James Ramsay committed Jan 31, 2015
2 parents b278f48 + 5c6fcc2 commit 678d3d2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 24 deletions.
8 changes: 3 additions & 5 deletions lib/transclude.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hercule",
"version": "0.1.1",
"version": "0.1.2",
"description": "Markdown transcluder",
"main": "./lib/main",
"scripts": {
Expand Down Expand Up @@ -33,7 +33,7 @@
"dependencies": {
"async": "^0.9.0",
"dashdash": "^1.7.0",
"lodash": "^2.4.1"
"lodash": "^3.0.0"
},
"devDependencies": {
"coffee-script": "^1.7.0",
Expand Down
11 changes: 4 additions & 7 deletions src/transclude.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ scan = (document, file, verbose, cb) ->
if match[WHITESPACE_GROUP]?
ref.whitespace = match[WHITESPACE_GROUP]

if document[match.index + match[0].length] is "\n"
ref.endOfLine = true

references.push ref

if verbose and references.length > 0
Expand Down Expand Up @@ -111,13 +108,13 @@ transclude = (file, parents = [], placeholderOverrides = [], verbose, cb) ->

if output?
if reference.whitespace
# Allows indentation to be preserved
# Preserve indentation if transclude is not preceded by content
output = output.replace /\n/g, "\n#{reference.whitespace}"

if not reference.endOfLine
# Allows inline replacement by removing new line at EOF
output = output.replace /\n $/, ""
# Remove new lines at EOF which cause unexpected paragraphs and breaks
output = output.replace /\n $/, ""

if verbose then console.error " Output:#{JSON.stringify output}"
refRegExp = new RegExp("{{#{reference.placeholder}}}", "g")
document = document.replace refRegExp, output

Expand Down
5 changes: 1 addition & 4 deletions test/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ describe 'hercule', ->

hercule.scan document, "", null, (err, references) ->
assert.equal references.length, 1
assert.equal references[0].endOfLine, null

done()

Expand All @@ -25,8 +24,6 @@ describe 'hercule', ->

hercule.scan document, "", null, (err, references) ->
assert.equal references.length, 2
assert.equal references[0].endOfLine, true
assert.equal references[1].endOfLine, null

done()

Expand Down Expand Up @@ -163,6 +160,6 @@ describe 'hercule', ->

hercule.transclude inputFile, null, null, false, (err, document) ->
if err then return cb err
assert.equal document, "The quick brown fox jumps over the lazy dog\n .\n"
assert.equal document, "The quick brown fox jumps over the lazy dog.\n"

done()
9 changes: 3 additions & 6 deletions test/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 678d3d2

Please sign in to comment.