Skip to content
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

Sections and subsections #138

Open
AWuhrmann opened this issue Dec 8, 2024 · 4 comments
Open

Sections and subsections #138

AWuhrmann opened this issue Dec 8, 2024 · 4 comments

Comments

@AWuhrmann
Copy link

Hi, I couldn't get headings with "#" working, is it supported ? I can't find anything on the documentation as well.

@BearToCode
Copy link
Owner

Did you apply a stylesheet?

@AWuhrmann
Copy link
Author

Not directly, but I have tailwindcss activated, and I noticed when I remove it from my app.css, the problem disappear (but tailwind as well...)

@BearToCode
Copy link
Owner

By default HTML documents have almost no styles attached to them. By using tailwind, even those are removed. You need to use your custom stylesheet to be able to style the resulting HTML. You can use one of the ones mentioned in the link I sent, or make your own.

@Wyrdix
Copy link

Wyrdix commented Jan 21, 2025

Don't know if that could be added in the repos but as an example @AWuhrmann what i did on my side is to have a plugin like so :

import type { Plugin } from 'carta-md';
import type { Element, Root } from 'hast';
import { visit } from 'unist-util-visit';

export type TailwindExtensionOptions = {};

function mapper(v: string): string | undefined {
	switch (v) {
		case 'h1':
			return 'h1';
		case 'h2':
			return 'h2';
		case 'h3':
			return 'h3';
		case 'h4':
			return 'h4';
		case 'h5':
			return 'h5';
		case 'h6':
			return 'h6';
		case 'strong':
			return 'font-bold';
		case 'em':
			return 'em';
		case 'ul':
			return 'list-disc list-inside';
		case 'ol':
			return 'list-decimal list-inside';
	}
}

export const tailwind = (options?: TailwindExtensionOptions): Plugin => {
	return {
		transformers: [
			{
				execution: 'sync',
				type: 'rehype',
				transform({ processor }): void {
					processor.use(() => {
						return (tree: Root) => {
							visit(tree, (node, index, parent) => {
								if (node.type !== 'element') return;

								const element = node as Element;
								element.properties.class = mapper(element.tagName);
							});
						};
					});
				}
			}
		]
	};
};

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

No branches or pull requests

3 participants