@@ -209,7 +209,30 @@ var qdocInlineNames = map[string]struct{}{
209209// raw-text mode, so the rest of the page is swallowed looking for a close
210210// that never comes. The tokenizer decodes these again, so the text a rule
211211// sees, and the text located in the source, are unchanged.
212- var qdocEsc = strings .NewReplacer ("&" , "&" , "<" , "<" , ">" , ">" ).Replace
212+ var qdocEscAll = strings .NewReplacer ("&" , "&" , "<" , "<" , ">" , ">" ).Replace
213+
214+ // An HTML comment, which survives escaping: `vale off` and `vale on` reach
215+ // the walker as comments, and a QDoc file writes them the same way any other
216+ // markup does.
217+ var qdocHTMLComment = regexp .MustCompile (`(?s)<!--.*?-->` )
218+
219+ func qdocEsc (text string ) string {
220+ spans := qdocHTMLComment .FindAllStringIndex (text , - 1 )
221+ if spans == nil {
222+ return qdocEscAll (text )
223+ }
224+
225+ var out strings.Builder
226+ last := 0
227+ for _ , s := range spans {
228+ out .WriteString (qdocEscAll (text [last :s [0 ]]))
229+ out .WriteString (text [s [0 ]:s [1 ]])
230+ last = s [1 ]
231+ }
232+ out .WriteString (qdocEscAll (text [last :]))
233+
234+ return out .String ()
235+ }
213236
214237// qdocArg strips the braces from a command argument.
215238func qdocArg (arg string ) string {
0 commit comments