pragdave / earmark

Markdown parser for Elixir
Other
859 stars 135 forks source link

How do I get colored syntax highlighting? #462

Closed CharlesIrvineKC closed 1 year ago

CharlesIrvineKC commented 1 year ago

In my LiveView app, I'm using Earmark to convert markdown to HTML. It's working great, but I have a problem. When I create a code block with '''exixir my_html ''' my code block doesn't get any colorization. Can you suggest how I might fix this?

I should mention the following as it might be related. Initially, the HTML generated by Earmark did not have any styling typical of HTML. It seems that this was a result of tailwind removing all default styling. I corrected this by pulling in a bunch of css from the LiveBook project.

My app.css file currently looks like this:

@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";

@import "./global.css";
@import "./components.css";
@import "./utilities.css";
@import "./live_view.css";
@import "./markdown.css";
@import "./ansi.css";
@import "./js_interop.css";
@import "./tooltips.css";
@import "./editor.css";
@import "./notebook.css";

Do you think that this hack from LiveBook might be causing my problem?

And BTW can you suggest another way of adding back default HTML styling?

Mohit-Vaswani commented 1 year ago

If your code block doesn't have any colorization when using Earmark in your LiveView app, it's likely because the CSS styles required for syntax highlighting are not being applied. This could be due to the CSS being overridden or not included properly in your app.

Based on the information you provided, it seems that the styling for your HTML generated by Earmark was initially missing because Tailwind CSS was removing the default styling. You mentioned that you added a bunch of CSS from the LiveBook project to correct this.

It's possible that the CSS from LiveBook is conflicting with or overriding the styles required for syntax highlighting. To troubleshoot this issue, you can try the following steps:

  1. Check the order of CSS imports in your app.css file. Make sure that the CSS file containing the styles for syntax highlighting is imported after the CSS from LiveBook. The order of imports can affect how styles are applied.

  2. Review the CSS classes and selectors in the LiveBook CSS files and see if they are affecting the code block styling. Look for any conflicting styles or rules that might be overriding the syntax highlighting styles. You may need to modify or remove certain CSS rules to resolve the conflict.

  3. Verify that the CSS file responsible for code block styling is being included properly in your app. Double-check the file path and make sure it is being loaded correctly.

Regarding adding back default HTML styling, there are a few approaches you can consider:

  1. Reset CSS: You can use a CSS reset or normalize stylesheet to reset the default styling of HTML elements. These stylesheets aim to provide consistent styles across different browsers and remove any unwanted styling that might be applied by default.

  2. Custom Styling: Instead of relying on default browser styles, you can create your own set of styles for HTML elements. This gives you full control over the appearance of your app. You can define styles for headings, paragraphs, links, code blocks, etc., based on your design requirements.

  3. CSS Frameworks: Consider using a CSS framework like Bootstrap or Bulma that provides default styling for HTML elements. These frameworks come with pre-defined CSS classes and components that you can use to style your app. However, be aware that using a CSS framework may introduce additional styles and may require customization to match your desired look and feel.

Remember to thoroughly test and validate any changes you make to ensure they don't introduce unintended side effects or conflicts with existing styles in your app.

CharlesIrvineKC commented 1 year ago

Hello Mohit, Thanks so much for taking the time to try to help me out. Actually, I finally got syntax coloring to work. I got help from Jose Valim from posting an issue to the makeup project. Here's the issue link: https://github.com/elixir-makeup/makeup/issues/58. -Charles