Open lukewatts opened 7 years ago
Ideally, I'd just like to be able to edit all the raw HTML content in the editor, so I could add classes to span and the headings etc. I feel very restricted not being able to edit the HTML when I want to.
Same here. You can currently type three backticks on a new line followed by the language code. For example:
```js
And it will turn into this:
<pre data-code="js">
Unfortunately, there's no way to change the code once it's created. This is something I'd like to improve, perhaps through a code tool.
I'd also like to switch to the following syntax based on GitHub Flavored Markdown:
<pre>
<code class="language-js">
...
</code>
</pre>
However, there's an issue with the way TinyMCE handles <code>
inside of <pre>
(it treats it as an inline element instead of a block element).
Changing code sections to special content blocks (via a code tool, for example) will resolve that, but at the expense of losing inline editing (it would open as a panel instead where you can enter a language and whatnot — same way the embed tool works).
Thanks for reminding me about this. I'm really interested in your thoughts on the proposed approach. I'd love to make this improvement for the next alpha release since it would be a breaking change.
The 3 backticks syntax is good. Didn't realise that was a possibility. I'll try that.
Markdown would be nice also for sure. Regarding the html editor a popout/slide-out panel to add html snippets or raw html could work, as long as They'VE can be made to leave it unaltered
Or perhaps a Html mode which simply switched the content with the html but you don't leave the main editor.
As you know, syntax highlighting in the browser is a bit challenging. There are a number of great libraries that tackle it these days, but nothing that lets you do it inline in a raw contentEditable
container. That said, we have a couple options:
<pre>
like we're doing nowPros:
Cons:
window.Postleaf
before initializing, otherwise the highlighted HTML will be saved in your post (likely causing future highlights to fail).<pre><code class="language-js">...</code></pre>
structure that GFM likes (mostly a semantic issue).This is a more elegant approach. The idea is similar to TinyMCE's code sample plugin where you can select a language and insert a code block via dialog.
Pros:
<pre><code class="language-js">...</code></pre>
structure that GFM likes.Cons:
Both have ups and downs. I prefer the plugin approach, but hopefully the current approach will suffice until the plugin API lands.
Heads up: I'm changing the triple backtick output from this:
<pre data-code="js">
To this:
<pre class="language-js">
It's still not the same as GFM, but it's a lot closer and still semantically correct.
I think that's a good solution! Works for what I had in mind at least
Why not enable HTML Mode and all happy ?
I write a lot of code related articles and I'd like to be able to add some classes to the pre tags in my posts so I can use PrismJS to add language based highlighting.
Is this possible right now, and if not is it planned?