:no_entry_sign: UNMAINTAINED :no_entry_sign: This used to check MDN docs against some tests and cleanup tasks while editing, but add-on SDK based add-ons are obsolete. Use https://github.com/mdn/doc-linter-webextension and https://github.com/mdn/doc-linter-rules instead.
Mozilla Public License 2.0
10
stars
8
forks
source link
Test that sidebar macros are not wrapped in <p> but in <div> #195
Here's a thing, for the detail-oriented: if you add the macro call on its own, then the editor wraps it in a
block. This then gets a 24-pixel margin-bottom, which pushes the content down the page, so it doesn't align properly with the sidebar or the ToC: https://i.imgur.com/zYpB21x.png
What I do here is manually wrap the macro call in a
, which stops the editor doing this. Is there a better approach?
Having a test that sidebar macros aren't wrapped in
How should the test work exactly? I see three options:
Let the extension know which macros this affects and mark them if not surrounded by a <div>. (macro blacklist)
Check whether the first (or last?) element is not a <div> but contains macros. (element position)
Search for all elements - except a few, which are allowed to hold macros - that only contain macros. (macro whitelist)
The first option is very conservative and requires updating in case new macros are added, but also strictly avoids false positives.
The second works independently of the macro name and only checks by element, which lets it match all macros but misses the macro if it is located somewhere else.
The third option is the most offensive one by finding all elements holding macros, expect a whitelist of macros like <p>{{CompatibilityTable}}</p>, so it finds the most but also is prone to false positives.
Which option do you think is the best? Or do you have another idea?
Thanks for thinking about possible implementations this quick already. I think I'm leaning towards option 1, possibly with a regex on the macro name (*Sidebar). It might help to collect a list of sidebar macro names here, so that it gets more clear about what we are talking about. Also, they are (should be) all in our macro whitelist.
@wbamberg wrote
How should the test work exactly? I see three options:
<div>
. (macro blacklist)<div>
but contains macros. (element position)The first option is very conservative and requires updating in case new macros are added, but also strictly avoids false positives. The second works independently of the macro name and only checks by element, which lets it match all macros but misses the macro if it is located somewhere else. The third option is the most offensive one by finding all elements holding macros, expect a whitelist of macros like
<p>{{CompatibilityTable}}</p>
, so it finds the most but also is prone to false positives.Which option do you think is the best? Or do you have another idea?
Sebastian
Thanks for thinking about possible implementations this quick already. I think I'm leaning towards option 1, possibly with a regex on the macro name (*Sidebar). It might help to collect a list of sidebar macro names here, so that it gets more clear about what we are talking about. Also, they are (should be) all in our macro whitelist.