Skip to content

Accept: text/markdown returns broken code blocks and tables #664

Description

@Anshumancanrock

The markdown content negotiation edge function mangles every fenced code block and table it touches.

Repro

curl -H 'Accept: text/markdown' https://project-hami.io/docs/get-started/deploy-with-helm

The Pod manifest comes back as:

 apiVersion : v1
 kind : Pod
 metadata :
 name : gpu - pod
 spec :
 containers :
 - name : ubuntu - container
 image : ubuntu : 22.04

Indentation is gone and every token is space-separated, so it no longer parses as YAML. Tables flatten the same way, /docs/userguide/device-supported comes back as one long line.

Cause is in netlify/edge-functions/markdown-negotiation.js: htmlToMarkdown() has no case for <pre>, <code> or <table>, so they hit the catch-all .replace(/<[^>]+>/g, " ") on L64. Prism puts each token in its own span, so that inserts a space between all of them, and L66 collapses what's left of the indentation.

Only affects clients that send Accept: text/markdown, so nothing looks broken in a browser. It's a 200 with silently wrong content though, which seems worse than not supporting the header at all.

Simplest fix is probably serving the source .md instead of converting the HTML. Happy to open a PR !

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions