Skip to content

Misc. bug: Pasted content from <code> blocks loses XML-based tags (HTML, XML, JSX) #18423

@dstjacques

Description

@dstjacques

Name and Version

version: 7442 (d0794e8)
built with Clang 19.1.5 for Windows x86_64

Operating systems

Windows

Which llama.cpp modules do you know to be affected?

llama-server

Command line

llama-server -hf <model>

Problem description & steps to reproduce

Summary

XML-based tags are stripped when copying and pasting a code block from the chat.
Reproduced in both Firefox and Chrome on Windows but this should be platform and browser agnostic.

The following HTML parse seems to be stripping the tags. There is already a fallback to the original text if the parse fails (line 69), but I wasn't sure the purpose of the HTML parse step to know if removing it entirely could be an option.

const doc = new DOMParser().parseFromString(rawCode, 'text/html');

A smaller/shorter term solution could be to just skip the HTML parse step (i.e. do the fallback logic of using the actual raw code) when XML tags are detected in the string or when the code is in one of the more seriously affected languages (e.g. HTML, JSX, XML).

How to reproduce

  1. New Chat (Any model and settings)
  2. Ask to Generate a small sample of XML
  3. Click "Copy code" on the resulting code block
  4. Paste the code into another program

Actual behavior

Code pasted from the chat into the other program:


    
        The Great Gatsby
        F. Scott Fitzgerald
        1925
        12.99
    


Expected behavior

Code pasted from the chat into the other program:

<?xml version="1.0" encoding="UTF-8"?>
<library>
    <book id="1">
        <title>The Great Gatsby</title>
        <author>F. Scott Fitzgerald</author>
        <year>1925</year>
        <price currency="USD">12.99</price>
    </book>
</library>

First Bad Commit

No response

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions