Skip to content
This repository was archived by the owner on Jun 25, 2020. It is now read-only.

Code block support #206

Merged
merged 8 commits into from
Feb 15, 2015
Merged

Code block support #206

merged 8 commits into from
Feb 15, 2015

Conversation

AndreyAkinshin
Copy link
Contributor

Now code blocks are highlighting with prettify

Now code blocks are highlighting with prettify
@laedit
Copy link
Member

laedit commented Feb 5, 2015

This is awesome, I think this syntax works with both liquid and razor.
But there is a few things:

  • there is one test failing on AppVeyor. I have improved the build, now if a test fail the all build will fail.
  • I think it's too linked to pretiffy, I think it can be the default choice but we can add the possibility to override the highlighter, like in Jekyll?

For the last one, if you haven't the time I will look into it.
I want to make a very flexible highlighting:

  • Support different highlighter
  • Be able to parse different syntax:
    • {% highlight c# %}
    • {{c#}}

@shiftkey, @JakeGinnivan, what do you think?

return text.Replace(m[0].Groups[0].Value, "").Trim();
text = text.Replace(m[0].Groups[0].Value, "");
var lines = text.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None).ToList();
while (lines.Any() && string.IsNullOrWhiteSpace(lines.First()))
Copy link
Member

Choose a reason for hiding this comment

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

Could this be done in a more LINQ-friendly way?

var nonEmptyLine = lines.Where(x => !String.IsNullOrWhiteSpace(x));
return String.Join(Environment.NewLine, nonEmptyLines).TrimEnd();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can't remove empty line in the middle of the text. My while removes only first empty lines. So, SkipWhile is needed. I will fix it.

Copy link
Member

Choose a reason for hiding this comment

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

Good point, 👍 to SkipWhile

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done (commit 0e5338f)

@shiftkey
Copy link
Member

shiftkey commented Feb 5, 2015

For reference, this is how Jekyll does it:

{% highlight ruby %}
def foo
  puts 'foo'
end
{% endhighlight %}

A couple of quick thoughts on the proposed syntax (contrasting against the above sample):

  • I've stopped doing "four spaces to indicate code" in Markdown for a while now - it feels fiddly unless you've set your editor up right. I feel the code fencing is so much nicer for managing this pain (shift-TAB to remove the whitespace, live a happy life) but that's specific to GitHub-Flavoured Markdown (which I don't believe is supported in MarkdownDeep
  • One of the other benefits of the previous point is that you can specify the language inline

That feels so much friendlier than needing to wrapp the language name in {{ foo }}

  • I do like dropping the "close tag" syntax

@AndreyAkinshin
Copy link
Contributor Author

@laedit, @shiftkey, thank you for feedback. I will try to add suport of differenet syntax for declare code blocks. About highlighters: I suggest to use some predefine set of highlighters and choose it in the config like in the following line:

highlighter: prettyify

What kind of additional highlighters is needed?

@AndreyAkinshin
Copy link
Contributor Author

There is a problem with the MarkdownDeep library. The issue about support for backtick fenced code blocks have been fixed only at 24 Feb 2014. But the current NuGet version of the library (0.5) is obsolete (last updated at August 20, 2012). So, it is impossible to implement nice support of markdown codeblocks with this version.

I suggest switching the project to CommonMark.NET for markdown processing. Advantages:

  • Great compatibility
  • Great performance
  • Full CommonMark specification support
  • Active developing

What do you think?

@AndreyAkinshin
Copy link
Contributor Author

Also I suggest using of CommonMark Spec 0.17 without specific highlighter. For example, lines

```ruby
def foo(x)
  return 3
end
```

will transform in

<pre><code class="language-ruby">def foo(x)
  return 3
end
</code></pre>

It is the HTML5 convention for code element. Prettify supports it. Next, a pretzel user can add any highlighter yourself. What do you think?

@shiftkey
Copy link
Member

shiftkey commented Feb 6, 2015

I'd totally be down for switching over to a more modern Markdown library

@laedit
Copy link
Member

laedit commented Feb 6, 2015

That is a great idea!
I'm good with that.

@laedit
Copy link
Member

laedit commented Feb 6, 2015

It seems that prettify always need the class="prettyprint".
But there is highlightjs and prism which support the HTML5 convention.

@AndreyAkinshin
Copy link
Contributor Author

It seems that prettify always need the class="prettyprint".

Yes, but you can add this class with one jQuery line. So, it is not a problem.

@laedit
Copy link
Member

laedit commented Feb 6, 2015

Good point.
Another way to do it: using an IContentTransform specific for each highlighter, if needed.

@AndreyAkinshin
Copy link
Contributor Author

Done.

@laedit
Copy link
Member

laedit commented Feb 6, 2015

In that case we can use highlightjs which does not require JQuery.
Or just indicates to the user how to choose and use an highlighter?

For the plugins it is a bit more complicated :)
We have the PR #157 waiting, but in the meantime you can add a class in the plugin folder which will implement IContentTransform.
We will transform it to an external plugin (dll) after the acceptation of PR #157.

@AndreyAkinshin
Copy link
Contributor Author

Ok, then I just will change prettyify+jQuery to highlightjs.

@AndreyAkinshin
Copy link
Contributor Author

Done.

@AndreyAkinshin
Copy link
Contributor Author

Any updates?

@laedit
Copy link
Member

laedit commented Feb 11, 2015

Sorry, I haven't got the time to merge it.
I intend to do it this week end, and to accept the PR #157 to be able to create the PrettifyContentTransformer plugin.

@laedit laedit merged commit cbf2abd into Code52:master Feb 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants