Skip to content

@md_str parses underscores in interpolated variables (Markdown.jl) #57265

Open
@abhro

Description

@abhro
Contributor

If there is an unescaped underscore in the string, the parser keeps looking for the underscore in the interpolated variable

Minimal working example:

julia> using Markdown

julia> a_b = 3.0
3.0

julia> md"a_b = $(a_b)"
ERROR: syntax: invalid syntax (incomplete #<julia: Base.Meta.ParseError(msg="ParseError:\n# Error @ none:1:3\n(a\n# └ ── Expected `)`", detail=Base.JuliaSyntax.ParseError(source=Base.JuliaSyntax.SourceFile(code=Base.SubString{String}(string="(a", offset=0, ncodeunits=2), byte_offset=0, filename="none", first_line=1, line_starts=Array{Int64, 1}(dims=(2,), mem=Memory{Int64}(8, 0x74123b497da0)[1, 3, 0, 0, 0, 0, 0, 0])), diagnostics=Array{Base.JuliaSyntax.Diagnostic, 1}(dims=(1,), mem=Memory{Base.JuliaSyntax.Diagnostic}(8, 0x74123b48ca40)[Base.JuliaSyntax.Diagnostic(first_byte=3, last_byte=2, level=:error, message="Expected `)`"), Base.JuliaSyntax.Diagnostic(first_byte=0, last_byte=0, level=#<null>, message=#<null>), Base.JuliaSyntax.Diagnostic(first_byte=0, last_byte=0, level=#<null>, message=#<null>), Base.JuliaSyntax.Diagnostic(first_byte=0, last_byte=0, level=#<null>, message=#<null>), Base.JuliaSyntax.Diagnostic(first_byte=0, last_byte=0, level=#<null>, message=#<null>), Base.JuliaSyntax.Diagnostic(first_byte=0, last_byte=0, level=#<null>, message=#<null>), Base.JuliaSyntax.Diagnostic(first_byte=0, last_byte=0, level=#<null>, message=#<null>), Base.JuliaSyntax.Diagnostic(first_byte=0, last_byte=0, level=#<null>, message=#<null>)]), incomplete_tag=:other))>)
Stacktrace:
 [1] top-level scope
   @ REPL[3]:1

julia> md"a\_b = $(a_b)"
  a_b = 3.0

julia> md"a_b = $a_b"
ERROR: UndefVarError: `a` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Stacktrace:
 [1] top-level scope
   @ REPL[6]:1

julia> md"a\_b = $a_b"
  a_b = 3.0

Activity

changed the title [-]`@md_str` parses underscores in interpolated variables[/-] [+]`@md_str` parses underscores in interpolated variables (Markdown.jl)[/+] on Feb 4, 2025
KristofferC

KristofferC commented on Feb 5, 2025

@KristofferC
Member

Is this a duplicate of #57265?

abhro

abhro commented on Feb 5, 2025

@abhro
ContributorAuthor

I don't know if you were talking about this being a duplicate of a different issue, but I think the link pasted here #57265 (comment) is to the same issue.

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @KristofferC@nsajko@abhro

        Issue actions

          `@md_str` parses underscores in interpolated variables (Markdown.jl) · Issue #57265 · JuliaLang/julia