Sublime Forum

'auto_close_tags': Is it possible to exclude things that are simply look like tags?

#1

Sometimes I edit HTML files that are in fact a mix of HTML and Markdown, and the Markdown parts often contain bare hyperlinks enclosed in angle brackets. It looks like this:

# Lorem ipsum

Lorem ipsum dolor sit amet.

<div style="background: #eee">

Beware dragons!

- <http://example.com/dragons.htm>
- <http://example.net/dragons.htm>

![](dragon.jpg)

</div>

Lorem ipsum dolor sit amet.

The problem is that Sublime Text thinks that <http://example.com/dragons.htm> and <http://example.net/dragons.htm> are HTML tags, and so if I have "auto_close_tags": true and type </, Sublime Text changes it not to </div> but </http:>.

Is there a workaround for this? Maybe it is possible to tell Sublime Text to auto-close only the tags I have white-listed (for example, only <div> and <aside>)?

Mistreating angled hyperlinks as tags also affects highlighting of matched tags.

0 Likes

#2

FWIW, Markdown is a superset of HTML.

Using Markdown syntax for markdown files makes auto-close-tag behave as expected :wink:

0 Likes

#3

Using Markdown syntax for markdown files makes auto-close-tag behave as expected :wink:

Yes, of course :smile: But there is a reason why those files are .htm and not .md. After they are finished, I view them in a browser, and instead to install a Markdown browser extension, I include the code to parse and render Markdown in the files themselves:

<script src="https://cdn.jsdelivr.net/npm/markdown-it@14.1.0/dist/markdown-it.min.js"></script>
<script>
window.onload = function() {
  const markdown = document.querySelector('noscript').innerHTML;
  const md = window.markdownit({
    html: true, linkify: false, typographer: true
  });
  const html = md.render(markdown);
  document.querySelector('body').innerHTML = html;
}
</script>
<noscript>

**strong** and <mark>mark</mark>

- <http://example.com>
- <http://example.net/foo%20bar.htm>

<aside style="background: #eee">

**strong** and <mark>mark</mark>

</aside>

| foo | bar |
|-----|-----|
| aaa | aaa |
| bbb | bbb |

</noscript>

If I simply change the filename extension from .htm to .md, the browser won’t know how to properly view them.

One workaround that I see is to open such an .htm file in ST and then change its filetype to Markdown:

But this is not really quick (click, scroll, hover, click) and is not really convenient in my workflow.

0 Likes

#4

Well, as HTML syntax/language doesn’t know about Markdown links encclosed in angled brackets they are treated like tags by all means. An application can’t do magic nor can it guess what you want to achieve - without giving it some hints. For a static syntax engine, adding some scripts is is not sufficient for it.

See also how highlighting treats your links as proper custom html tags. There are no rules in HTML spec, which would tell us to not treat those links as tags.

Commenting out scripts also causes browsers to treat them as tags.

grafik

1 Like