errata-ai / vale

:pencil: A markup-aware linter for prose built with speed and extensibility in mind.
https://vale.sh
MIT License
4.44k stars 153 forks source link

Vale on/off comments do not work on titles in RST #340

Open mxsasha opened 3 years ago

mxsasha commented 3 years ago

This RST:

.. vale off

this text should be fine
------------------------

.. vale on

with a style that forbids the word "text", still generates an error:

 3:6  error  Use 'words' instead of 'text'  example-styles.example 

In my understanding, no error should be raised in this case.

With the exact same setup, this file (correctly) does not generate an error.

.. vale off

this text should be fine

.. vale on

Tested with .vale.ini as:

[*.{md,rst,txt,json}]
BasedOnStyles = example-styles

and the only style in example-styles being:

extends: substitution
message: Use '%s' instead of '%s'
level: error
swap:
  text: words

Seen on Mac OS 11.2.1, vale 2.9.1 installed through homebrew. It's a bit too complicated (and I don't know Go) to debug further on my own.

jdkato commented 3 years ago

The problem here seems to be a bug with rst2html.

.. vale off

this text should be fine
------------------------

.. vale on

This text should be fine.

.. vale off

this text should be fine

.. vale on

If you run rst2html on the above file, you'll get

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.16: http://docutils.sourceforge.net/" />
<title>this text should be fine</title>
</head>
<body>
<div class="document" id="this-text-should-be-fine">
<h1 class="title">this text should be fine</h1>

<!-- vale off -->
<!-- vale on -->
<p>This text should be fine.</p>
<!-- vale off -->
<p>this text should be fine</p>
<!-- vale on -->
</div>
</body>
</html>

The vale off comment appears after the heading in the output, even though it appears before the heading in the input.

RCheesley commented 1 year ago

We have this issue as well in the Mautic docs, which causes our checks to fail as we need to use camel case where a part of the product is included in the heading.

RCheesley commented 9 months ago

I get a similar but maybe related issue with Ascii docs (in this case, Antora). I have some pages which relate to 'My Account' and so forth, so it's erroring on Google.FirstPerson, but I can't wrap the heading of the page in a Vale statement without getting a critical error:

Level 0 sections can only be used when doctype is book ascidoctor.js