Closed chalu closed 7 years ago
@chalu So disclaimer that I haven't attempted this, but you should be able to...
Listen for the event syntax-highlight
using the listener to process the code. Updating the code
property of the event.
https://github.com/chjj/marked#highlight
UPDATE: Here is a quick jsfiddle to get you going. https://jsfiddle.net/stramel/qfbwsLj6/
I made some changes that broke the fiddle. Here is how my code is actually structured : https://paste.fedoraproject.org/paste/borN7tKz17m7ok8orervPl5M1UNdIGYhyRLivL9gydE= I am using Polymer 2.x with ES6 classes. e.detail.code gets set to the transformed / highlighted code that is displayed in the browser. I just need to figure out why I still don't see any syntax highlight.
Thanks a lot.
It just appears that the highlightjs styles aren't applying. The dom looks correct at least in my fiddle to match what you have.
Yes. You are correct. I got it working with this hack / solution:
.hljs {}
became [slot="markdown-html"] pre > code .hljs {}
What would be the appropriate way to apply external CSS to a shadow root, without having to modify the external CSS rules ?
Thanks!
Currently, there isn't a good way to get around it. Maybe once we offer a 2.0 (non-hybrid), you could extend marked-element
to do that a bit easier... I think what you said now is probably the best way to handle it.
Thanks. One more thing, the syntax-highlight event is not documented here: https://www.webcomponents.org/element/PolymerElements/marked-element/elements/marked-element I had to look at the source code for marked-element to figure this out on line 303 : https://github.com/PolymerElements/marked-element/blob/master/marked-element.html#L303
Would be nice to also include a code-highlight example within the docs. Is this something I can contribute to this element ?
Ah, good point. Yeah, feel free to put a PR updating the documentation.
Great. Doing so ..
I made a pull request. Kindly review here : https://github.com/PolymerElements/marked-element/pull/68
On Mon, Jun 5, 2017 at 3:37 PM, Michael Stramel notifications@github.com wrote:
Ah, good point. Yeah, feel free to put a PR updating the documentation.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PolymerElements/marked-element/issues/66#issuecomment-306177167, or mute the thread https://github.com/notifications/unsubscribe-auth/AAQ3PnJCw6KwGrWVLG6MYtpje61UI4ylks5sA_aDgaJpZM4NuJ7e .
-- Kind Regards Odili Charles Opute Twitter : @chaluwa *Author : *http://goo.gl/v54jy http://goo.gl/v54jy
Description
The
marked-element
element has no clear or configurable way of highlighting code, e.g with highlight js.Expected outcome
Code blocks should be highlight-able using marked.js highlight option
Actual outcome
marked-element only fires a 'syntax-highlight' event which I can listen for. There is no way to plug in and highlight code
Steps to reproduce
1.Load highlight css with
marked-element
element in the page. 4.Inside the marked-element, add a