Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #169 #170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ First of all, **thank you** for contributing, **you are awesome**! :)

If you have an idea or found a bug, please [open an issue](https://github.com/cebe/markdown/issues/new) on github.

If you want to contribute code, there a few rules to follow:
If you want to contribute code, there a few rules to follow:

- I am following a code style that is basically [PSR-2](http://www.php-fig.org/psr/2/) but with TABS indentation (yes, I really do that ;) ).
- I am following a code style that is basically [PSR-2](https://www.php-fig.org/psr/psr-2/) but with TABS indentation (yes, I really do that ;) ).
I am not going to nit-pick on all the details about the code style but indentation is a must. The important part is that code is readable.
Methods should be documented using phpdoc style.

Expand All @@ -31,6 +31,6 @@ where the input file contains the Markdown and the output file contains the expe
You can run the tests after initializing the lib with composer(`composer install`) with the following command:

vendor/bin/phpunit

To create a new test case, create a `.md` file a`.html` with the same base name in the subfolders of
the `/tests` directory. See existing files for examples.
24 changes: 24 additions & 0 deletions GithubMarkdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,28 @@ protected function renderText($text)
return parent::renderText($text);
}
}

/**
* @inheritDoc
*
* Allows escaping newlines to create line breaks.
*
* @marker \
*/
protected function parseEscape($text)
{
$br = $this->html5 ? "<br>\n" : "<br />\n";

# If the backslash is followed by a newline.
# Note: GFM doesn't allow spaces after the backslash.
if ($text[1] === "\n") {

# Return the line break
return [["text", $br], 2];
}

# Otherwise parse the sequence normally
return parent::parseEscape($text);

}
}
6 changes: 6 additions & 0 deletions tests/github-data/issue-169.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<p>test \
with trailing space</p>
<p>test <br />
without trailing space</p>
<p>test<br />
without leading space</p>
8 changes: 8 additions & 0 deletions tests/github-data/issue-169.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test \
with trailing space

test \
without trailing space

test\
without leading space