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

HTML entities in input to Rouge #8

Open
lowjoel opened this issue Apr 17, 2016 · 3 comments
Open

HTML entities in input to Rouge #8

lowjoel opened this issue Apr 17, 2016 · 3 comments

Comments

@lowjoel
Copy link
Contributor

lowjoel commented Apr 17, 2016

Continuation from #6.

In HTML, editors like to use     to preserve whitespace. Non-breaking space isn't recognised by Rouge to be same as space, so it does not recognise the syntax properly.

untitled
(look at the pink whitespace)

Maybe we should extend the "replace_br" configuration to be more general, "preprocess HTML" or some configuration setting like that, where contiguous non-breaking whitespace is replaced with normal spaces instead?

This is getting pretty nasty.

@lowjoel
Copy link
Contributor Author

lowjoel commented Apr 17, 2016

For now I've got this:

@@ -16,2 +16 @@ module HTML
-          node.css("br").each { |br| br.replace("\n") } if replace_br
-          text = node.inner_text
+          text = preprocess_html(node)
@@ -30,0 +30,9 @@ module HTML
+      def preprocess_html(node)
+        node.css("br").each { |br| br.replace("\n") } if replace_br?
+        result = node.inner_text
+        return result unless preprocess_html?
+
+        result.gsub!("\u00A0", ' ')
+        result
+      end
+
@@ -43,2 +51,2 @@ module HTML
-      def replace_br
-        context[:replace_br] || false
+      def replace_br?
+        context[:replace_br] || preprocess_html?
@@ -46,0 +55,4 @@ module HTML
+      def preprocess_html?
+        context[:preprocess_html] || false
+      end
+

@JuanitoFatas if you're fine with this I'll cook up a spec and PR.

@lowjoel
Copy link
Contributor Author

lowjoel commented May 4, 2016

@JuanitoFatas any comments?

@JuanitoFatas
Copy link
Owner

@JuanitoFatas if you're fine with this I'll cook up a spec and PR.

Sorry for late response, let's go with this first :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants