Skip to content

Strip hashes from markdown headers#228

Open
FireController1847 wants to merge 2 commits into
microsoft:mainfrom
FireController1847:add-headers
Open

Strip hashes from markdown headers#228
FireController1847 wants to merge 2 commits into
microsoft:mainfrom
FireController1847:add-headers

Conversation

@FireController1847

@FireController1847 FireController1847 commented Mar 3, 2026

Copy link
Copy Markdown

It seems more reasonable to strip the hashes and use the inherent nature of the symbol's children to determine the associated levels for each header. This will tie into a PR in VS Code, in addition to microsoft/vscode-codicons#442, which adds icons to further distinguish between header levels.

This is how I fetched the level heading in an extension I was designing using Lua. It's very possible and, imo, more practical since hashes are markdown-specific anyway:

---@param symbols LuaSymbol[]
---@return StructureNode[]
function GetDocumentStructure(symbols, level)
    local structure = {}
    if not level then
        level = 1
    end
    for i = 1, #symbols do
        local symbol = symbols[i]
        local line = 0
        if symbol.selectionRange and symbol.selectionRange.start then
            line = symbol.selectionRange.start.line
        elseif symbol.range and symbol.range.start then
            line = symbol.range.start.line
        end
        local name = symbol.name:gsub("#", ""):gsub("^%s+", ""):gsub("%s+$", "")
        local node = MakeNode(name, "h" .. level, line)
        if (symbol.children) then
            node.children = GetDocumentStructure(symbol.children, level + 1)
        end
        table.insert(structure, node)
    end
    return structure
end

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

Successfully merging this pull request may close these issues.

1 participant