Tell GitHub to Render Markdown Pages with .gitattributes
Caleb Hearth

Caleb Hearth @calebhearth

About: Dungeon Webmaster, Open Sourcerer, and breakfast THAC0 enthusiast. https://pub.calebhearth.com/@caleb

Location:
Denver, CO
Joined:
Feb 22, 2018

Tell GitHub to Render Markdown Pages with .gitattributes

Publish Date: Nov 23 '24
0 2

Articles on Hearthside are written in Markdown (GitHub-flavored), but the file extension is .md.yaml as they also make use of Jekyll-style front matter. My Frontmatter gem requires that files it handles end in .yaml or .yml, so this is necessary.

Because of the file extension, GitHub until this week did not render the Markdown correctly. Instead articles have been highlighted if they were written in YAML completely, which really messes up the Syntax highlighting even beyond not giving a rendered preview.

I’m not sure why I never thought to look into it in the last several years of writing this way, but it turns out that you can tell GitHub’s Linguist tool what type of language a file type should match, so to do that I added this to my project’s .gitattributes:

*.md.y*ml linguist-language=markdown 
Enter fullscreen mode Exit fullscreen mode

Read More

Comments 2 total

  • Sloan the DEV Moderator
    Sloan the DEV ModeratorNov 30, 2024

    Hi there, we encourage authors to share their entire posts here on DEV, rather than mostly pointing to an external link.

    Sharing your full posts helps ensure that readers don’t have to jump around to too many different pages, and it helps focus the conversation right here in the comments section on DEV.

    To be clear, the DEV Terms state:

    Posts must contain substantial content — they may not merely reference an external link that contains the full post.

    Also, if you share your full post, you have the option to add a canonical URL directly to your post. This helps with SEO if you are reposting articles!

Add comment