Skip to content

Syntax highlighter cleanup #1352

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

Closed
wants to merge 23 commits into from

Conversation

haarg
Copy link
Member

@haarg haarg commented Sep 15, 2014

This cleans up the syntax highlighter markup and styles.

Rather than using the syntax highlighter's built in configuration mechanism that abuses the class attribute, use distinct attributes and proper classes to configure it in the markup. Then read that information in javascript and feed it to the syntax highlighter. The new markup matches up with the recommendations in the HTML5 spec. It also allows the API to provide syntax highlighting configuration, which is the first half of implementing #605.

Also, stop trying to apply custom styles to the syntax highlighter for the border and background, etc. Instead, reset the syntax highlighter itself to inherit from parent attributes, and wrap it in a pre tag to get the borders, background, fonts, etc.

@haarg haarg force-pushed the syntax-highlighter-cleanup branch 4 times, most recently from bc03eef to 15ccbc8 Compare September 16, 2014 08:17
@haarg
Copy link
Member Author

haarg commented Sep 16, 2014

I've added some more to this PR, including highlighting multiple lines, re-highlighting when you click on lines, and icons for the source view sidebar.

@@ -55,21 +55,10 @@

<div class="content">
<% IF !module.binary %>
<pre class="brush: <% filetype %>; class-name: 'highlight'; toolbar: false;" id="source"><% source %></pre>
<pre id="source" class="line-numbers pod-toggle<% IF module.sloc > 0; " pod-hidden"; END %>" data-pod-lines="<%
module.pod_lines.map(->(l){ l.0+1 _ "-" _ (l.0+l.1) }).join(', ')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind using a different variable name in the map?
It can be hard to tell the difference between the lowercase L and the 1...
and with the template syntax for array subscripting...
when I first saw this line I thought it said 1.0+1.1 and wondered why...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, will do.

@rwstauner
Copy link
Contributor

I'm glad you moved the stuff to a separate file... I was thinking about doing that last night :-)
Sounds good so far, I'll review it a little more later.
Thanks!

@haarg haarg force-pushed the syntax-highlighter-cleanup branch from 0d0575d to d91656a Compare September 16, 2014 15:00
@haarg
Copy link
Member Author

haarg commented Sep 16, 2014

Rebased, fixing the variable name in the template.

@haarg haarg force-pushed the syntax-highlighter-cleanup branch 2 times, most recently from ed22a1e to c769426 Compare September 20, 2014 14:34
@@ -109,7 +109,7 @@ sub view : Private {
br => [],
caption => [],
center => [],
code => [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you comment on what values might be coming through this attribute and from where?
I don't see why we should allow the class attribute to come through from pod for any tag.

@rwstauner
Copy link
Contributor

@haarg This stuff is great, thanks!
Sorry about the barrage of line comments, but it was a lot to read from top to bottom and i was trying to keep my thoughts straight.
A few code comments would make this super awesome!

@haarg
Copy link
Member Author

haarg commented Sep 22, 2014

I've added some comments and done some minor refactoring to reduce duplication.

The basic idea with the data- attributes is that they can be provided in the markup. We set some on the source page and some using javascript, but they could also be included in the markup returned by the API for Pod documents. That's why they are allowed by the HTML filter. This means the Pod can include syntax highlighting hints, like requested in #605. I've written a Pod::Simple extension we'll be able to use to provide this, Pod::Simple::XHTML::WithHighlightConfig.

@haarg haarg force-pushed the syntax-highlighter-cleanup branch from 7f82378 to 70c2bf2 Compare September 22, 2014 12:23
@haarg
Copy link
Member Author

haarg commented Sep 22, 2014

Also, the particular attributes/classes I'm using are based on Prism, an alternate syntax highlighter I'm considering trying out, which is smaller and hopefully has less bugs. Even if we don't change the syntax highlighter, I think it's a reasonable way to mark up the data. Much better than the syntax highlighter's built in method that abuses the class attribute using a braced comma separated format.

@haarg haarg force-pushed the syntax-highlighter-cleanup branch 2 times, most recently from 4ba6401 to 307b3b9 Compare September 26, 2014 13:33
This makes the classes used for highlighting match up with the HTML5
recommendations, and removes the use of the ugly braced config stuffed
into the class attribute.  It also opens up the option of the pod->html
converter providing syntax highlighting configuration in a reasonable
format.
Instead of applying styles to syntax highlighter blocks and trying to
match verbatim sections to that, just use the normal <pre> styles.  This
simplifies the rules needed, and removes the need to extend the syntax
highlighter's css rules.
@haarg haarg force-pushed the syntax-highlighter-cleanup branch from 307b3b9 to d3d4d21 Compare September 26, 2014 13:53
@haarg
Copy link
Member Author

haarg commented Sep 26, 2014

I've rebased this again, but with two important changes. be338ed adds additional limits to what can be passed through the HTML filter, disallowing classes on all elements. And in 7ac339e I've added validation to the syntax highlighter config attributes that are allowed through.

@rwstauner
Copy link
Contributor

totally awesome.
let's merge it.

@haarg
Copy link
Member Author

haarg commented Sep 27, 2014

Rebased and merged as 7c1d100

@haarg haarg closed this Sep 27, 2014
@haarg haarg deleted the syntax-highlighter-cleanup branch September 27, 2014 19:32
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

Successfully merging this pull request may close these issues.

2 participants