Skip to content

Commit ef2b350

Browse files
Stop telling an agent to send a Markdown fold as HTML (#1030)
* Stop telling an agent to send a Markdown fold as HTML A fold written the way the basecamp skill says, <details> and <summary> around Markdown, made the CLI warn that the content held HTML tags and to pass --format html to send it as written. That is the one thing the skill says not to do: --format html stores the post exactly as written, so every paragraph, table, list and fold in it renders touching. Agents that followed the warning, or the writing guide that said the same, posted with no space between blocks. The warning now leaves out raw HTML that holds only a fold's own tags, as it already leaves out mention markup. A fold written as HTML, a summary holding other tags, or HTML beside a fold still warns. * Exempt only bare fold tags with text between them from the HTML warning Scanning raw HTML for tag names let a comment or declaration inside a fold pass as fold markup. Match the whole raw HTML instead: every "<" must open <details>, <summary> or their closing tags, so a comment, an attribute or any other tag keeps the warning.
1 parent b41435c commit ef2b350

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

‎internal/commands/richtext_format_test.go‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ func TestCommentsCreateRejectsUnknownFormat(t *testing.T) {
120120
// Content that used to be sent as written because it looked like HTML is now
121121
// read as Markdown. The caller is told once, on stderr, how to keep the old
122122
// result — unless the format was chosen explicitly, or the only tags are the
123-
// mention and attachment markup Markdown content carries routinely.
123+
// mention and attachment markup Markdown content carries routinely, or a fold's
124+
// <details> and <summary>, which the basecamp skill tells agents to write in
125+
// Markdown. Warning on a fold pointed agents at --format html, where every block
126+
// is stored touching.
124127
func TestRichTextHTMLInMarkdownWarns(t *testing.T) {
125128
tests := []struct {
126129
name string
@@ -139,6 +142,13 @@ func TestRichTextHTMLInMarkdownWarns(t *testing.T) {
139142
{"html in a tilde fence", []string{"create", "789", "~~~\n<p>x</p>\n~~~"}, false},
140143
{"html in indented code", []string{"create", "789", "Example:\n\n <p>x</p>"}, false},
141144
{"angle brackets in prose", []string{"create", "789", "A Vec<String> here"}, false},
145+
{"a fold in markdown", []string{"create", "789", "The fix landed.\n\n<details><summary>▶ How it was measured</summary>\n\n- Five **runs**\n\n</details>"}, false},
146+
{"a fold written inline", []string{"create", "789", "Done. <details><summary>Steps</summary>ran it twice</details>"}, false},
147+
{"a fold written as html", []string{"create", "789", "<details><summary>Steps</summary><p>ran it twice</p></details>"}, true},
148+
{"html beside a fold", []string{"create", "789", "<p>A</p>\n\n<details><summary>Steps</summary>\n\nran it\n\n</details>"}, true},
149+
{"a summary holding other tags", []string{"create", "789", "<details><summary><strong>Steps</strong></summary>\n\nran it\n\n</details>"}, true},
150+
{"a fold holding a comment", []string{"create", "789", "<details><summary>Steps</summary><!-- a note -->\n\nran it\n\n</details>"}, true},
151+
{"a fold tag with an attribute", []string{"create", "789", "<details data-x=\"<p>\"><summary>Steps</summary>\n\nran it\n\n</details>"}, true},
142152
}
143153
for _, tt := range tests {
144154
t.Run(tt.name, func(t *testing.T) {

‎internal/richtext/richtext.go‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,11 @@ func MarkdownToHTML(md string) string {
484484
}
485485

486486
// HasRichTextHTML reports whether MarkdownToHTML would keep any raw HTML from
487-
// md other than <bc-attachment> markup: whether the Markdown parser finds an
488-
// inline tag or an HTML block whose tag is in richTextTags. HTML inside code is
489-
// not raw HTML to the parser, so it never counts.
487+
// md other than <bc-attachment> markup and a fold's own tags: whether the
488+
// Markdown parser finds an inline tag or an HTML block whose tag is in
489+
// richTextTags. HTML inside code is not raw HTML to the parser, so it never
490+
// counts. A fold written the way the basecamp skill says, <details> and
491+
// <summary> around Markdown, is Markdown content, so it never counts either.
490492
func HasRichTextHTML(md string) bool {
491493
if md == "" {
492494
return false
@@ -507,7 +509,7 @@ func HasRichTextHTML(md string) bool {
507509
default:
508510
return ast.WalkContinue, nil
509511
}
510-
if isRichTextTag(raw) && !reLeadingAttachmentTag.Match(raw) {
512+
if isRichTextTag(raw) && !reLeadingAttachmentTag.Match(raw) && !isFoldMarkup(raw) {
511513
found = true
512514
return ast.WalkStop, nil
513515
}
@@ -516,6 +518,19 @@ func HasRichTextHTML(md string) bool {
516518
return found
517519
}
518520

521+
// reFoldMarkup matches raw HTML made only of a fold's own bare tags, <details>,
522+
// <summary> and their closing tags, with text between them. Every "<" in it
523+
// must open one of those four tags, so a tag with attributes, any other tag, a
524+
// comment or a declaration does not match.
525+
var reFoldMarkup = regexp.MustCompile(`(?i)^(?:[^<]|</?(?:details|summary)>)*$`)
526+
527+
// isFoldMarkup reports whether raw HTML holds only a fold's own tags, <details>
528+
// and <summary>, with nothing but text between them. An HTML block that also
529+
// holds anything else, such as a whole fold written as HTML, is not.
530+
func isFoldMarkup(raw []byte) bool {
531+
return reFoldMarkup.Match(raw)
532+
}
533+
519534
// reLeadingAttachmentTag matches a <bc-attachment> open or close tag at the
520535
// start of raw HTML: the mention and attachment markup Markdown content carries
521536
// routinely.

0 commit comments

Comments
 (0)