Menu

#1430 Scintilla HTML code style recognition

Duplicate
open
nobody
5
2024-03-05
2022-02-02
Wittrup
No

Hello

Using Notepad++ with the plugin Indent By Fold, it is noticed that Scintilla does not understand HTML code style very well. With HTML in this case is meant a file that also contains CSS-styling and Javascript.

The matter is somewhat described at IndentByFold FAQ here:
https://indentbyfold.readthedocs.io/en/latest/faq.html

Q: In CSS, } brackets don’t indent left like they do in the C-styled languages. Between <style> tags in HTML, indentation doesn’t happen at all.

Q: The plugin indents wrong in certain if else situations in various languages

For instance this gets indented as such:

        <style>
            * {
            margin: 0;
            padding: 0;
            border: 0;
            }

While this is the desired result:

        <style>
            * {
                margin: 0;
                padding: 0;
                border: 0;
            }

JavaScript code indents like this:

    <script>
        let center = [6.58979, 45.40107];

        const map = new mapboxgl.Map({
        container: 'map',
        zoom: 13,
        center: center,
        pitch: 76,
        bearing: 150,
        style: 'mapbox://styles/mapbox/outdoors-v11',
        hash: false
    });

    function myFunction(args) {
        if (checkSomething(arg)) {
            doSomething(arg);
            } else {
            doSomethingElse(arg);
        }
    }

The expected result are:

    <script>
        let center = [6.58979, 45.40107];

        const map = new mapboxgl.Map({
            container: 'map',
            zoom: 13,
            center: center,
            pitch: 76,
            bearing: 150,
            style: 'mapbox://styles/mapbox/outdoors-v11',
            hash: false
        });

        function myFunction(args) {
            if (checkSomething(arg)) {
                doSomething(arg);
            } else {
                doSomethingElse(arg);
            }
        }

Which is support by MDN Web Docs, Google JavaScript Style Guide and more:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else
https://google.github.io/styleguide/jsguide.html
https://google.github.io/styleguide/htmlcssguide.html#Block_Content_Indentation

I am aware that SciTE FAQ mentions explicit folds here .

Discussion

  • Neil Hodgson

    Neil Hodgson - 2022-02-02
    • Priority: 8 --> 5
     
  • Neil Hodgson

    Neil Hodgson - 2022-02-02

    Lexers are now part of the Lexilla project https://www.scintilla.org/Lexilla.html and issues are tracked on https://github.com/ScintillaOrg/lexilla

    CSS inside HTML is lexed in one style, the default style, 0. So the braces aren't seen as syntax.

    The const map line should be seen as start of a fold - it appears foldable to me.

    For the } else { something like the cpp lexer's fold.at.else property could be copied.

     
  • Zufu Liu

    Zufu Liu - 2024-03-05
    • Group: Initial --> Duplicate
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.