News for hackers. Stuff that matters.
Re:Linting HTML using CSS by nates on Saturday March 11, 2017 @08:48PM (#13848424)
Re:Linting HTML using CSS by oneeyedpigeon on Sunday March 12, 2017 @06:57AM (#13850175)
I toyed with something similar a few years ago, although didn't pursue it to this depth. One issue, though: border is definitely not the right way to highlight elements in this manner since it affects layout. I'd go with outline instead.
Re:Linting HTML using CSS by mercer on Monday March 13, 2017 @03:17AM (#13855824)
Does it affect layout if you use box-sizing: border-box;?
Re:Linting HTML using CSS by tannhaeuser on Sunday March 12, 2017 @12:43AM (#13849255)
Soundly checking HTML, including all kinds of customization and more is possible using SGML.

[1]: http://sgmljs.net/blog/blog1701.html

Re:Linting HTML using CSS by oneeyedpigeon on Sunday March 12, 2017 @10:20AM (#13850754)
You could probably also do something similar to the article, providing your document is XML-valid, using XSLT. This would keep the advantage that you just load your document in a browser (having added a temporary stylesheet link either manually or dynamically) but would support more powerful validation. It could be made into a browser extension so you're just a one-click away from validation with in-page feedback.
Re:Linting HTML using CSS by tannhaeuser on Sunday March 12, 2017 @11:13AM (#13850995)
Of course, you can also validate XHTML using the provided DTDs if you take out the SGML-specific bits, using a (DTD-)validating XML parser (or indeed use XSLT as you say). But SGML has tag omission/inference, empty elements/HTML "void" elements, attribute short forms, unquoted attributes, Wiki syntaxes/markdown, and other features desired or even required for mere parsing mainstream HTML. As to using XHTML, I'm not sure it has a bright future. Last I've worked with it was like ten years ago (xsl-stylesheet processing instruction etc. on IE6; newer browsers don't seem to support it anymore).

FYI: SGML is way more powerful than XML, and its grammar formalism is identical to that of XML because XML was designed as a simplified subset of SGML. Though Relax NG, and also XML Schema, can theoretically express richer grammars than SGML, they can't be used for HTML due to lack of tag inference and other short syntax features, and the features that Relax NG has over SGML benefit data-oriented rather than document-oriented use cases (eg. the use cases that JSON and other serialization formats are arguably better suited for than markup in the first place IMO).

sgmljs.net can run (also) in the browser, so can also validate HTML5 in the browser.

Disclaimer: my project

Re:Linting HTML using CSS by oneeyedpigeon on Sunday March 12, 2017 @12:17PM (#13851327)
I've had success with xhtml and xslt processing on the server-side. The fact that it's xhtml is incidental; that it's xml-valid means I can use a wealth of established tools to modify the content, and easily write my own. I don't mind too much about xml support in the browser, although I've found xslt to still be supported in chrome - e.g. for rendering RSS feeds as HTML.
Re:Linting HTML using CSS by tux1968 on Sunday March 12, 2017 @05:25AM (#13849972)
Your comment sent me down a multi-hour rabbit hole.. thank you. I ended up reading a fair bit about Marcus Reichardt's initiative toward a SGML DTD for HTML5.1. However, i was unable to find a place where a tool or said DTD was available for download. Do you happen to have a link?
Re:Linting HTML using CSS by tannhaeuser on Sunday March 12, 2017 @06:05AM (#13850062)
For now the full DTD grammar can be downloaded from the "Restrictive DTD" tab link of the full paper eg. [1] via copy/paste. I intend to be make it accessible on a permanent URL once I get more feedback/review comments. It can be processed using the venerable OpenSP/OpenJade package (install it with "sudo apt-get install opensp" on Debian/Ubuntu or "sudo port install opensp" on Mac/MacPorts; don't know the MacBrew equivalent, though). I'm using my own sgmljs SGML system (public release upcoming/pending).

[1]: http://sgmljs.net/docs/w3c-html51-dtd.html

Re:Linting HTML using CSS by carapace on Sunday March 12, 2017 @03:38PM (#13852603)
This is fantastic! (Forgive me, but s/detailled/detailed/ in the link at the bottom.)
Re:Linting HTML using CSS by tannhaeuser on Sunday March 12, 2017 @04:18PM (#13852830)
Thanks very much. Keep your findings coming, I'll be happy for any feedback.
Re:Linting HTML using CSS by SpaceManiac on Saturday March 11, 2017 @08:23PM (#13848341)
This is a good choice of selectors, but I wonder what styles one should apply to <meta>, <script>, or <link> tags that will get them to actually display anything. Some fiddling in Firefox didn't reveal the solution.
Re:Linting HTML using CSS by foo123456 on Saturday March 11, 2017 @09:06PM (#13848487)
display:block will show them. Those elelemnts are not impossibly visible, they are just display:none by default
Re:Linting HTML using CSS by err4nt on Saturday March 11, 2017 @11:42PM (#13849016)
If they are inside the <head> you have to display: block that first, try something like:

    head, meta, style, script, link { display: block; }
Re:Linting HTML using CSS by bennettfeely on Saturday March 11, 2017 @08:39PM (#13848399)
Is there a reason the * selector is needed on the first example or am I missing something? I believe [style] { } would get the same result.
Re:Linting HTML using CSS by tomatsu on Sunday March 12, 2017 @07:56AM (#13850311)
The '*' there has no effect whatsoever. It doesn't even change the specificity.
Re:Linting HTML using CSS by yokohummer7 on Sunday March 12, 2017 @04:43AM (#13849856)

  a:not([href])  
  a[href="#"],  
  a[href=""],  
  a[href*="javascript:void(0)"] { … }
Wait, what should I use instead then?
Re:Linting HTML using CSS by jacobr on Sunday March 12, 2017 @04:48AM (#13849866)
The button element should be used for interaction that is not navigation to a different url.
Re:Linting HTML using CSS by jontro on Sunday March 12, 2017 @05:39AM (#13849998)
What about anchors using name?
Re:Linting HTML using CSS by lexicality on Sunday March 12, 2017 @07:12AM (#13850211)
They've been deemed obsolete with HTML5 - you should use the id attribute on the element the <a> would be naming.
Re:Linting HTML using CSS by oneeyedpigeon on Sunday March 12, 2017 @07:00AM (#13850180)
Always supply an href so JavaScript-less viewers can still activate the link. Attach events via JavaScript rather than HTML attributes.
Re:Linting HTML using CSS by tompazourek on Sunday March 12, 2017 @04:54AM (#13849889)
I was thinking the same when I saw that... Not sure if it's viable, but maybe buttons?
Re:Linting HTML using CSS by remy_luisant on Sunday March 12, 2017 @03:11AM (#13849587)
Reminds me how some video games would use really garish default textures, so that the errors in texturing stand out.

I believe Thief 1 and 2 have done this, but I may be wrong.

Re:Linting HTML using CSS by deoxxa on Sunday March 12, 2017 @04:39AM (#13849843)
It's also similar to what Microsoft does (did?) with Windows during development[0] - text that hasn't been translated yet is shown with a whole bunch of meaningless diacritical marks and replacement characters so it stands out.

[0]: https://en.wikipedia.org/wiki/Pseudolocalization#Pseudolocal...

Re:Linting HTML using CSS by toomanybeersies on Sunday March 12, 2017 @04:56AM (#13849896)
The Source Engine (of Half Life and Counter Strike fame) uses a checkered black and bright pink texture for missing textures. It really is garish, as I discovered when playing Garry's Mod back in the day.
Re:Linting HTML using CSS by tvararu on Monday March 13, 2017 @04:19PM (#13861947)
John Romero learned this in his early days at ID Software: it's crucial that you can still boot the game even when things are missing, but make them very apparent.

Source: somewhere in this video https://www.youtube.com/watch?v=E2MIpi8pIvY

Re:Linting HTML using CSS by rangibaby on Sunday March 12, 2017 @10:04AM (#13850690)
Doom2 has the classic "AASHITTY"
Re:Linting HTML using CSS by jwdunne on Sunday March 12, 2017 @05:05AM (#13849920)
Interesting idea though I think the best choice is a VLI linting tool configured to check these and editor integration.

You could also use JS and log the info to console. Last thing you want to do is this making its way into production and it probably will: sods law.

I just think the most efficient approach is to log violations to a console with exact line numbers.

Re:Linting HTML using CSS by lendk on Monday March 13, 2017 @04:31AM (#13856118)
Hi guys i already made a github repo as a follow up from this article you can check it here: https://github.com/lendk/Lint-HTML-with-SCSS-CSS
Re:Linting HTML using CSS by nodesocket on Saturday March 11, 2017 @09:17PM (#13848535)
Very cool trick. If interested, there is a node cli module which tests against W3.

     npm install html-validator-cli -g
     cd "$HOME"/Sites/mysite
     html-validator --verbose --file=index.html
Re:Linting HTML using CSS by grav on Sunday March 12, 2017 @07:00AM (#13850183)
Inline styles are what keeps my React code maintainable :-)
Re:Linting HTML using CSS by jzig on Sunday March 12, 2017 @11:39AM (#13851129)
Why isn't there an HTML linter in the same way there is ESLint for JavaScript?
Re:Linting HTML using CSS by dredmorbius on Sunday March 12, 2017 @01:22PM (#13851762)
There is tidy. I was going to say "but it's not kept up with standards", but find whilst researching this comment that it has been extended to HTML5.

https://www.w3.org/People/Raggett/tidy/

Search shows a few other options as well: https://duckduckgo.com/?q=html+linter&t=ftas&ia=web

Unless I'm misreading your question.

Re:Linting HTML using CSS by 5_minutes on Sunday March 12, 2017 @08:09AM (#13850335)
It would be nice if this was all bundled in some easy to include package
Re:Linting HTML using CSS by adzicg on Saturday March 11, 2017 @08:26PM (#13848353)
broken XML leading to browsers applying inconsistent closing tags is a much bigger issue than missing attributes or inline CSS

this kind of linting can't spot broken document structure

Re:Linting HTML using CSS by Xorlev on Saturday March 11, 2017 @08:28PM (#13848358)
Sure, but lets say you have well-formed HTML tags. At that point you're looking for things semantically "weird" as opposed to structurally wrong. This helps there.
Re:Linting HTML using CSS by stan_rogers on Saturday March 11, 2017 @10:16PM (#13848731)
HTML isn't XML. HTML is older.
Re:Linting HTML using CSS by recursive on Saturday March 11, 2017 @11:40PM (#13849008)
The rules for this are specified in the html5 spec. Also, some tags are not allowed to be closed, and others are only optionally closed. (like li and p)
Re:Linting HTML using CSS by combatentropy on Saturday March 11, 2017 @09:51PM (#13848648)
If you have to apply CSS to find elements with inline styles, I think you have a more serious problem.

And telling everyone that every one of their images must have an alt tag is draconian. Sometimes an image is purely decorative. Sometimes an image doesn't convey any more than the paragraph beside it. Often an alt tag is written in a perfunctory way, or even when it isn't, it doesn't truly make things better for the blind person. I think they should be at the writer's discretion.

Re:Linting HTML using CSS by alanh on Sunday March 12, 2017 @01:04AM (#13849318)
Your comment is actively harmful. You are spouting off a strong opinion that hasn't benefitted from any actual knowledge of the topic — or from actually reading the article — or from thinking about it for a more than a second.

As the article correctly states, an alt attribute should always be present; explicitly empty values signal that no alt content is needed for a screen reader.

An image without the alt attribute is not even valid HTML. Try it yourself: https://validator.w3.org/nu/#textarea

I think it's smart that alt is required. Many of us would otherwise blithely continue on without considering accessibility. (Sadly, most of us still do, and we build tools and abstractions that "automatically" set the alt to something, be it an empty string or the file name… defeating the purpose of inviting the author to explicitly create an alt content.)

Back to your comment - if you are of the habit of shitting on ideas just to provoke a defense of them in order to ultimately learn something, I suggest you find a more constructive approach to learning… you could have googled it for 15 seconds and could have instead written, “I thought making a rule of always including alt was dumb, but I googled it and discovered that it's required by the HTML standard because x, y, and z”

Re:Linting HTML using CSS by dgellow on Sunday March 12, 2017 @03:36AM (#13849660)
I think you overreacted.

There is no "shitting on idea" in the parent comment (if you disagree, could you highlight what you mean by that?).

Also, "actively harmful"? What do you mean? He only nuanced the article message.

Re:Linting HTML using CSS by combatentropy on Sunday March 12, 2017 @03:35AM (#13849656)

   > You are spouting off a strong opinion that hasn't benefitted
   > from any actual knowledge of the topic
   > or from thinking about it for a more than a second.
I made my first website in the late '90s and have been doing web apps for a living for over a decade. I have thought about it quite a bit over the years, and I have been on both sides of the issue.

   > just to provoke a defense
I was not looking for a defense. I was trying to help others not feel guilty for not doing something that I think seldom makes a real difference. I'm thinking of most of the articles I have read, and I'm thinking of the difference to a screen reader in either case: (1) stopping to read some alt text or (2) simply silently skipping over it and just reading the article. In many cases I think it's best not to break the flow or waste the person's time.

   > An image without the alt attribute is not even valid HTML.
The spec says it is for a few cases (https://html.spec.whatwg.org/multipage/embedded-content.html...). But yes, for the case I'm thinking of it insists we explicitly put alt="". I think this is tedious and overstepping its bounds. If a writer doesn't want to put alt text for one of his images, he shouldn't have to. He chose to write an article instead of doing nothing.

And I'm not really talking about being lazy. I'm talking about not wasting the reader's time. If you tell everyone it's better to put an alt tag than nothing at all, then you're going to get a lot of poorly written and annoyingly redundant alt text. If someone writes a text-based article, then it is handicap-accessible, with or without alt tags. What might be less accessible would be an article typeset with images (which is rare nowadays anyways) --- but even then, computers are so good now at deciphering images that even that might not be much of a problem either.

Re:Linting HTML using CSS by matt4077 on Sunday March 12, 2017 @06:53AM (#13850164)
Just say you were wrong. This is embarrassing.
Re:Linting HTML using CSS by combatentropy on Sunday March 12, 2017 @03:27PM (#13852534)
Why do you think I was wrong?
Re:Linting HTML using CSS by aidenn0 on Saturday March 11, 2017 @10:21PM (#13848740)
According to TFA, an image with no alt tag will cause some screenreaders to read the src, so a purely decorative image should instead have a null alt tag.
Re:Linting HTML using CSS by alanh on Sunday March 12, 2017 @01:15AM (#13849363)
Yep. (And with the fingerprinting / cache-busting most of us do for our assets these days, the result is painful. Listen: https://www.dropbox.com/s/blln31qfzviwf7k/say-0ffe34b4e04c2b...)
Re:Linting HTML using CSS by pinum on Saturday March 11, 2017 @10:06PM (#13848700)
This makes some sense, but it occurs to me that a blind person has no way to distinguish between an image that has no alt tag because it would be meaningless, and an important image that the author simply didn't think to write an alt tag for.

alt="(Decoration)" would clear it right up and only takes a few seconds.

Re:Linting HTML using CSS by singlow on Saturday March 11, 2017 @10:31PM (#13848770)
alt="" means decoration - screenreaders will ignore it.
Re:Linting HTML using CSS by cfv on Saturday March 11, 2017 @09:57PM (#13848677)
I like using these to diagnose what kind of lemon a client just brought for maintenance, but they can be pretty nice to ensure you got your final product right too.