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

markdown-to-json refuses to work on some aspects #563

Closed
Roky3029 opened this issue Mar 25, 2024 · 9 comments
Closed

markdown-to-json refuses to work on some aspects #563

Roky3029 opened this issue Mar 25, 2024 · 9 comments

Comments

@Roky3029
Copy link

My issue is pretty self-explanatory.

I just have a piece of markdown coming from a file and I pass it through the <Markdown></Markdown> component and it just works... more or less.

If I pass something like _Hello World_ it converts it to italics. However, using # to specify headings won't work and neither do tables.

I don't get any console warning or error, and I just can't find what's wrong

@quantizor
Copy link
Owner

Try wrapping your content with String.raw, often processing React templates perform on strings messes them up

@Roky3029
Copy link
Author

Try wrapping your content with String.raw, often processing React templates perform on strings messes them up

Not working, I keep getting the same error, the content is showed and italics, bold... is formatted correctly, however, I keep getting titles (using #) as normal text and tables are not shown

@quantizor
Copy link
Owner

Gotcha. Any chance you could put together a minimal reproduction? It's hard to help without sample code.

@Roky3029
Copy link
Author

Yeah, sure.

My markdown file looks something like this:

---
title: "Some title"
subtitle: "Some subtitle"
date: "some date"
author: "author"
---

Markdown content

### Title

(just a normal markdown file)

then I receive that file in /[slug].tsx in which slug is the filename. I pass that slug to a function that selects the data of the file just like this:

import matter from 'gray-matter' // This is used to separate the data between --- and the content itself
import fs from 'fs'

const getPostContent = (slug: string) => {
	const folder = 'src/posts/'
	const file = `${folder}/${slug}.md`
	const content = fs.readFileSync(file, 'utf-8')
	const matterResult = matter(content)
	return matterResult
}

and then on my component I just pass to the <Markdown> component the content which is not data between ---

const PostPage = (props: any) => {
	const slug = props.params.slug
	const post = getPostContent(slug)

	return (
		<div className='flex items-center justify-center flex-col'>
			<article className='prose lg:prose-xl px-5'>
				<Markdown>{post.content}</Markdown>
			</article>
		</div>
	)
}

The weird thing about it is that some weeks ago it worked absolutedly perfect and then all of a sudden it stopped formatting what I said above.
These are some screenshots:

Markdown code

| Team              | Driver 1         | Driver 2          |
| ----------------- | ---------------- | ----------------- |
| Red Bull Racing   | Verstappen       | **Ricciardo**     |
| Ferrari           | Leclerc          | **Hamilton**      |
| Aston Martin      | **Sainz**        | Stroll            |
| Williams          | _Kimi Antonelli_ | Albon             |
| Stake Kick Sauber | Bottas           | **Hulkenberg**    |
| Mercedes          | Russell          | **Alonso**        |
| McLaren           | Norris           | Piastri           |
| Alpine            | Gasly            | **_??? Unknown_** |
| Visa CashApp RB   | _Liam Lawson_    | Tsunoda           |
| Haas              | _Oliver Bearman_ | Magnussen         |

image

As you can see, bold and italics are working just fine, but the table isn't

@quantizor
Copy link
Owner

At least visually from that screenshot it looks like the table is intact, are you referring to missing styling or something? The content is aligned into columns as you would expect.

@quantizor
Copy link
Owner

I'll try to reproduce this in a sandbox, thanks for the sample code

@Roky3029
Copy link
Author

Hmmm, that's true.
I thought it wasn't correct because before it was showed with paddings, little separators and all of that, and most importantly, centered.

Now that I think of it, it might not be a problem of the <Markdown> component. It could be all happening because of the Tailwind styles I'm applying in the <article> parent element.

I'll try to investigate this and let you know if this was the problem

@Roky3029
Copy link
Author

Turns out it was just a Tailwind problem because I accidentally removed the plugin which allowed me to use the prose class.

Thanks for the help anyways.

@quantizor
Copy link
Owner

Ah ok, thanks for using the library :-)

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

2 participants