News for hackers. Stuff that matters.
Re:Writing HTML by Hand by err4nt on Wednesday September 20, 2023 @12:33AM (#37580404)
I write HTML by hand and one thing that's come in handy is HTML's built-in functionality for author-defined custom elements. We use ICON-LIST which wraps a UL and optionally an SVG if you don't want to use the default checkmark, and STAR-RATING which displays a rating out of 5 SVG stars. They aren't my most-used, that's probably P or A or LI or DIV or SPAN by number, but they're some of the most important I use frequently!
Re:Writing HTML by Hand by semanticc on Wednesday September 20, 2023 @03:25AM (#37581390)
Are you talking about web components?
Re:Writing HTML by Hand by tannhaeuser on Wednesday September 20, 2023 @03:58AM (#37581619)
Was wondering as well. You can just go ahead and use your own element straight away. You just won't get tag omission and other short forms, but you aren't getting those by using the questionable JS API for declaring elements (or proposed new APIs for HTML fragment parsing in browsers) either.

The use case mentioned - custom list bullets - can be implemented using CSS btw [1]. Not that I'd advocate for it; like all things CSS, it involves lookup of obscure and rare custom syntax, questionable layering a la "content:", suggestion of orthogonality that isn't really there, and browser support troubles.

[1]: https://web.dev/css-marker-pseudo-element/

Re:Writing HTML by Hand by Vinnl on Wednesday September 20, 2023 @05:48AM (#37582295)
Web Components are generally considered to be a set of standards, and Custom Elements is one of them. The others are Shadow DOM and HTML Templates (the <template> element).
Re:Writing HTML by Hand by chrismorgan on Wednesday September 20, 2023 @01:36AM (#37580719)
<g> is interesting there: it’s an SVG element. SVG and MathML are fun in HTML syntax, because it becomes a little more XMLly when parsing them: XML-style self-closing tags (<tag/>) actually work, and there’s no such thing as a void element (e.g. <br> which has no closing tag because it has no contents). This can lead to fun problems in overly-simplistic filtering, e.g. <script/>alert()</script> is a syntax error in SVG or in XML-syntax HTML, is swallowed and does nothing inside SVG-in-HTML (it’s an empty script tag followed by a text node and an extraneous end tag), and alerts inside HTML (the trailing slash in the start tag reports a syntax error but they don’t do anything). This is ripe for security issues from smuggling stuff. There’s also fun like whether <script>alert("&lt;")</script> alerts “<” (SVG/XML syntax HTML) or “&lt;” (HTML). These sorts of things are why it is said: use a real HTML parser if you’re working with HTML.

In the rest of HTML syntax, adding a trailing slash does exactly nothing—it’s just ignored by the parser¹. For my part, I firmly recommend against writing it if you’re using HTML syntax, because it gives the false impression that it does something; rather, there’s a hard-coded list of elements that have no contents and thus no closing tag. It’s not uncommon to find people writing their />, but it’s practically never consistently applied, e.g.:

  <meta charSet="utf-8"/>    ← ²
  <link rel="…" href="…"/>
  <link rel="…" href="…">    ← Where’s my /, hmm?
So if you tried loading this with XML syntax (which is still very much a thing), you’d hit a parse error. And remember, this was put in as an XHTML compatibility measure (though I’m honestly not convinced it was worth it—without the special handling, you’d just have ended up with an attribute named / with an empty string value, which isn’t so bad).

HTML/XML polyglot is a surprisingly thorny issue, and my experience is that a lot of JavaScript libraries make assumptions that don’t hold in XML-syntax documents and thus won’t work properly. In practice, almost no one uses XML syntax for anything new, and foreign content (SVG/MathML) is the last remnant of widely-used XML in HTML.

—⁂—

¹ This is a very slight simplification. Look into the self-closing flag in the spec if you’re interested in the details.

² I think that wrong capitalisation of charSet comes from Next.js, because every time I’ve seen it, Next.js has been present. It has irritated me for years, but never quite enough to dig in and find the source and beg them to fix it. No idea if Next.js supports using XML-syntax HTML, but if it does, that meta charSet will be invalid, because XML syntax is case-sensitive and it’s supposed to be charset—though I think it will still work in practice because of the charset detection algorithm actually working on the bytes, not the XML/HTML syntax, and being case-insensitive. And if Next.js doesn’t support using XML syntax, I wish they’d stop generating trailing slashes, too, because they’re just a waste of time.

Re:Writing HTML by Hand by tannhaeuser on Wednesday September 20, 2023 @03:14AM (#37581306)
Yeah the trailing slash cargo cult just goes to show the author has no idea what he/she is doing. Even more pointless is a pretentious space before the slash. It appears many extant uses of the bogus slash result from WordPress filters and their fragile nature (never change a running WP system aka WP trainwrecks) rather than manual insertion.
Re:Writing HTML by Hand by chrismorgan on Wednesday September 20, 2023 @04:39AM (#37581892)
Mind you, the space before the slash can be load-bearing in HTML syntax, if you use an unquoted attribute value:

  <img src=x/>   =  <img src="x/">
  <img src=x />  =  <img src="x">
Re:Writing HTML by Hand by jraph on Wednesday September 20, 2023 @05:31AM (#37582205)
> Even more pointless is a pretentious space before the slash

It could also be an habit, and not really a harmful one. You can argue against it with convincing arguments, but in the end, there's nothing fundamentally wrong with it. It's understood by the parser.

The space before the slash once was advised for compatibility with old browsers when writing polyglot html. Some old browsers would not understand the slash, but this would not be an issue with a space. This is mostly irrelevant today but habits stick.

And with the gotcha exposed by my sibling comment, maybe it's better to stick with the space after all when using the slash. And I can see how wanting to explicitly close the tag is compelling, even if it has its drawbacks.

Re:Writing HTML by Hand by vvendigo on Wednesday September 20, 2023 @01:37AM (#37580724)
My most used tag is DIV, because I write more games/apps than docs. By hand using Vanilla JS and HTML.
Re:Writing HTML by Hand by okaleniuk on Wednesday September 20, 2023 @02:53AM (#37581188)
I do all the https://wordsandbuttons.online/ by hand, and this is my top 10:

    2527 p
    2047 a
    1318 span
    1078 td
    918 b
    537 tr
    531 sub
    499 br
    401 i
    393 table
Re:Writing HTML by Hand by CapstanRoller on Wednesday September 20, 2023 @03:30AM (#37581429)
Do you use a particular JS library for the visualizations? They look great!
Re:Writing HTML by Hand by okaleniuk on Wednesday September 20, 2023 @04:17AM (#37581737)
No, it's all vanilla JS.

Moreover, I don't even have internal dependencies, every page is written from scratch (with a pinch of copy-paste). This is a hobby project, and I like to program, so I'm just not interested in code reuse.

Re:Writing HTML by Hand by nologic01 on Wednesday September 20, 2023 @02:57AM (#37581203)
For many purposes it is needlessly verbose to write html by hand. Thats why markdown became popular.

But if more people do it and report their usage patterns one could maybe create a "super-markdown", i.e., the closest you could get to mapping html flexibility without the annoying XML verbosity.

Re:Writing HTML by Hand by tannhaeuser on Wednesday September 20, 2023 @03:06AM (#37581254)
> the closest you could get to mapping html flexibility without the annoying XML verbosity

Aka SGML.

Though while you can hide those away in an external DTD, SGML of course needs lots of markup declaration ([1]) for HTML "void" (empty) elements, tag inference, and enumerated attribute short forms, and then still more for markdown short references.

[1]: https://sgmljs.net/docs/whatwg-html200129-dtd.html

Re:Writing HTML by Hand by tincholio on Wednesday September 20, 2023 @07:31AM (#37582895)
Arguably, org-mode provides a "better markdown", but it's decidedly more niche.
Re:Writing HTML by Hand by alanbernstein on Wednesday September 20, 2023 @08:48AM (#37583484)
I like org-mode, but one of my gripes is that code block syntax is too clunky.
Re:Writing HTML by Hand by tincholio on Thursday September 21, 2023 @04:17AM (#37594693)
It's definitely heavier than Markdown's, but then again, it can do a lot more... In practice, if you're using Emacs, it doesn't really matter, because you can just insert a code block, and specify the language (if you're not using Babel stuff)
Re:Writing HTML by Hand by xigoi on Wednesday September 20, 2023 @07:54AM (#37583066)
I've created xidoc[0], which is meant to make writing HTML (as well as LaTeX) easier and more powerful.

[0] http://xidoc.nim.town/

Re:Writing HTML by Hand by MrVandemar on Wednesday September 20, 2023 @03:32AM (#37581447)
HTML is how I write.

I struggled with Markdown (and various other mark up formats) for a long time, until I realised that, for me, nothing beats plain HTML for simplicity and expressive power.

I now use HTML the way people generally use markdown: as an open, easy to read, easy to write, plain-text format for taking notes, writing articles, expressing thoughts, and so on.

I didn't really choose HTML, I just sort of noticed that I was using it. It seems like an unconscious decision, like a river flowing downhill, finding its own path.

Most used tag would be <p>, because I write a lot of essays and things with paragraphing. As well as other structural elements such as headings and lists, I lean into <time>, <cite>, <abbr> a lot.

I tend to use the 'optional' form. I don't close <p>'s and <li>'s unless required.

Re:Writing HTML by Hand by the_gipsy on Wednesday September 20, 2023 @03:49AM (#37581553)
I really love Elm's way of writing html. It's like writing html without closing tags, just indentation.
Re:Writing HTML by Hand by rudasn on Wednesday September 20, 2023 @08:35AM (#37583369)
Check out haml. Quite similar approach I think.
Re:Writing HTML by Hand by nikolaplejic on Wednesday September 20, 2023 @08:50AM (#37583503)
Not equivalent, but arguably more useful for manual authoring: Emmet [0] was all the range a while back, and I still use it to write HTML. It comes naturally if you're used to writing CSS-like selectors, and mostly gets out of the way.

DSL-wise, I've rather enjoyed Clojure's Hiccup [1].

[0] https://emmet.io/

[1] https://github.com/weavejester/hiccup

Re:Writing HTML by Hand by naniwaduni on Wednesday September 20, 2023 @10:59AM (#37585045)
When writing html for documents and not as code, indenting everything really lost its luster to me, it's really nice to have the content root flush with the left margin.
Re:Writing HTML by Hand by Akronymus on Wednesday September 20, 2023 @11:14AM (#37585251)
For me personally, elmish offers even better usability. But thats probably down to simple familiarity.
Re:Writing HTML by Hand by pests on Wednesday September 20, 2023 @04:00AM (#37581638)
The optional form is weird looking coming from the XHTML era where we were trained on the auto-closing form.

Looking up elements that support no closing tag:

html, head, body, p, li, dt, dd, option, thead, th, tbody, tr, td, tfoot, colgroup

Makes sense if you think about it. Basically everything is pretty well defined and its obvious what next tag should close the context. <td> for example obviously ends when you come across another <td>, another <tr>, or the required </table>

Re:Writing HTML by Hand by pbhjpbhj on Wednesday September 20, 2023 @05:10AM (#37582086)
><td> for example obviously ends when you come across another <td>, another <tr>, or the required </table> //

Only a madman would nest tables!!

/me crying in 2000's web design.

Re:Writing HTML by Hand by pests on Wednesday September 20, 2023 @07:24PM (#37591377)
Nope, nesting works! The required ending tag on table means any nested table will open a new context and then any <tr> or <td> will now scope to that table and will until the second tables closing </table>.

  <table>
  <tr>
  <td>
    <table>
    <tr>
    <td> table-cell-inside-table
    </table>
  </table>
Re:Writing HTML by Hand by MrVandemar on Wednesday September 20, 2023 @06:16AM (#37582454)
I lived through the XHTML era; when I was doing web-design I adopted it for many projects. It just seemed right to rigorously enforce a formal approach, and I suspect it reduced errors.

Took me a long time to train myself out of <br/> afterwards though.

But the optional-style works I think for writing. Especially if you're just writing a document. If you don't have site-menus, a search bar, social-media sharing icons, javascript libraries and all the other paraphenalia and page-furniture of a website, then you are left with a lean and structured file.

Re:Writing HTML by Hand by foobarbecue on Wednesday September 20, 2023 @08:24AM (#37583298)
You mean </br>, presumably.
Re:Writing HTML by Hand by throwaway_no on Wednesday September 20, 2023 @08:30AM (#37583334)
<br /> is a self closing tag. This is used in XML / XHTML for elements that have no contents.

It is a valid short form of <br></br>

Re:Writing HTML by Hand by thinkingemote on Wednesday September 20, 2023 @08:35AM (#37583368)
technically <br></br> is not allowed to have an end tag in the HTML spec

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/br

so it should be <br> on its own or <br />

Re:Writing HTML by Hand by naniwaduni on Wednesday September 20, 2023 @11:03AM (#37585110)
A silly corner of the spec, considering that this is a spec that specifies exactly how to handle e.g. misnested elements and admits plenty of other things that read intuitively as standardized sloppiness.
Re:Writing HTML by Hand by midasuni on Wednesday September 20, 2023 @08:30AM (#37583336)
No. <br></br> is shortened to <br/>
Re:Writing HTML by Hand by foobarbecue on Wednesday September 20, 2023 @11:29AM (#37585445)
Wow, thanks everyone... it seems I've misunderstood this all these years.
Re:Writing HTML by Hand by pests on Wednesday September 20, 2023 @07:20PM (#37591354)
You see this a lot in React/JSX too. Saves seme typing and noise inserting a component with no children.
Re:Writing HTML by Hand by brainzap on Wednesday September 20, 2023 @06:22AM (#37582492)
but how do you do images or video, they need some extra magic work
Re:Writing HTML by Hand by MrVandemar on Wednesday September 20, 2023 @07:27AM (#37582870)
I'm not sure I understand your question. <img> is the tag you use for an image, and there are tags to embed video.
Re:Writing HTML by Hand by brettermeier on Wednesday September 20, 2023 @08:10AM (#37583203)
Yes, it's really simple. And if he meant sizing, "height" and "width" parameters still work in an img-tag:

<img src="img.png" height="100px">

(also the other parameter is set to "auto" automatically, at least in Firefox)

Re:Writing HTML by Hand by erhaetherth on Thursday September 21, 2023 @03:00AM (#37594104)
pretty sure you're not supposed to use px in the height attribute. they are pixels.

the width will be set to match the aspect ratio but your browser will have to DL the image first. which probably doesn't matter unless you have content to the left/right of it, then it'll get bumped when the image loads. layout shift is a nasty thing.

Re:Writing HTML by Hand by brettermeier on Thursday September 21, 2023 @06:25AM (#37595664)
But you can do it and it works. And because it's about taking quick notes, it's not really about the beauty of the layout or layout shifts, isn't it?
Re:Writing HTML by Hand by kome on Wednesday September 20, 2023 @08:37AM (#37583386)
<img>? <video>?

but i'm not sure if i understand the question...

Re:Writing HTML by Hand by GoblinSlayer on Wednesday September 20, 2023 @11:50AM (#37585726)
In web 2.0 everything is done by javascript.
Re:Writing HTML by Hand by SPBS on Wednesday September 20, 2023 @08:28AM (#37583318)
<a href="">links</a> are such a pain to write though. Probably the biggest annoyance when I write in raw html.
Re:Writing HTML by Hand by adrianmsmith on Wednesday September 20, 2023 @08:34AM (#37583364)
But is [abc](http://...) any better? I can never remember which brackets to use, and I've been using Markdown for years now. I never have a problem remembering the HTML syntax.
Re:Writing HTML by Hand by alanbernstein on Wednesday September 20, 2023 @08:42AM (#37583427)
IMO, yes, it is so much more concise that it is worth memorizing.

https://mtsknn.fi/blog/how-to-remember-markdowns-link-syntax...

Think of it as a function call (mnemonically, it doesn't need to make sense conceptually).

Re:Writing HTML by Hand by fabianholzer on Wednesday September 20, 2023 @05:16PM (#37590291)
My problem exactly. My memory seems not to work well for symbols which rely mostly on position. Is it URL first or link text first, and do I put the URL in round or square brackets? Same with formatting: Is the first * italics or bold? I can remember <i> and <b> much better, and will trade off a bit of verbosity for not straining my memory anytime.
Re:Writing HTML by Hand by umpalumpaaa on Wednesday September 20, 2023 @07:46PM (#37591560)
Easy trick to remember it: [Button](url)

The [ and ] are ascii art for a button - in between goes what is clickable (title) and then comes the url.

Re:Writing HTML by Hand by MrVandemar on Thursday September 21, 2023 @04:16AM (#37594684)
The lack of internal consistency, especially the link syntax, has always been something I struggled with with Markdown. But that's about the first sensible way to remember it that I've seen.
Re:Writing HTML by Hand by jasonm23 on Thursday September 21, 2023 @03:53AM (#37594498)
yes of course.

> I can never remember which brackets to use

and that is patently untrue, as you just demonstrated.

Re:Writing HTML by Hand by adrianmsmith on Thursday September 21, 2023 @04:41AM (#37594871)
I had to look it up before writing my comment :)
Re:Writing HTML by Hand by theandrewbailey on Wednesday September 20, 2023 @09:30AM (#37583878)
10 years ago, I got frustrated adding in all the closing tags for my blog's articles, so I implemented Markdown. It made writing long articles so much easier that I wouldn't dare go back and wonder why I waited so long to do it.
Re:Writing HTML by Hand by lenkite on Thursday September 21, 2023 @03:59PM (#37603390)
How do you create TOC ? Navigation bars ?
Re:Writing HTML by Hand by MrVandemar on Thursday September 21, 2023 @06:08PM (#37605085)
There's a difference between a web-site and a document. When you fire up a word-processor do you produce a document with "navigation bars".

As for TOC, I've never written anything that strictly needs one. I do have "hxtoc" on my laptop, but I've never needed it.

I do publish some of my writing to my website, and I discuss the minimal tooling I use here: https://brett.coulstock.id.au/site-colophon.html

Re:Writing HTML by Hand by bambax on Wednesday September 20, 2023 @04:08AM (#37581693)
I don't exactly write "HTML" by hand if by HTML one means (as seems to be implied in the article) long text documents with HTML tags in it. For that I use markdown because it's faster and much easier to read.

But I do write HTML templates by hand when I code webapps; it's cleaner and more efficient than use some kind of library.

I tend to use DIVs with custom data- attributes; I don't know if it's a good or bad practice but I'm not familiar enough with other approaches and I'm used to it.

I also code SVGs by hand and it's surprisingly easy and straightforward; most (not all, but most) drawings can be approximated by combining elementary shapes (instead of paths).

Re:Writing HTML by Hand by fuzztester on Wednesday September 20, 2023 @07:18AM (#37582817)
>I also code SVGs by hand and it's surprisingly easy and straightforward; most (not all, but most) drawings can be approximated by combining elementary shapes (instead of paths).

Interesting. Do you have any examples of thise approximations?

Re:Writing HTML by Hand by bambax on Wednesday September 20, 2023 @08:46AM (#37583463)
Here's the Y of HN that I posted as a comment a couple of months ago:

https://news.ycombinator.com/item?id=35898741

Re:Writing HTML by Hand by fuzztester on Thursday September 21, 2023 @12:20AM (#37593187)
Thanks.
Re:Writing HTML by Hand by numlock86 on Wednesday September 20, 2023 @06:34AM (#37582538)
I hate writing HTML. Yes, there's IDE support for inserting <s and >s but it's just annoying. Same for lists of classes or attributes etc.

For everyone else feeling like me: Try pug (formerly jade) or rather it's CLI variant pug-cli. You can reuse stuff and even have JS in it to iterate through things or give it parameters, all while still feeling pretty vanilla.

https://pugjs.org/api/getting-started.html

Re:Writing HTML by Hand by lapcat on Wednesday September 20, 2023 @07:03AM (#37582711)
I'm old school and write all of my HTML by hand in BBEdit: https://www.barebones.com/products/bbedit/
Re:Writing HTML by Hand by slmjkdbtl on Wednesday September 20, 2023 @07:21AM (#37582828)
I use whatever programming language to generate HTML string from a simple function like h("div", { class: "box" }, [ ... ]), so I can use variables, loops etc.
Re:Writing HTML by Hand by willmartian on Wednesday September 20, 2023 @08:10AM (#37583202)
You might like my tiny library: https://hdot.dev/

It is a bit terser:

h.div.class('box)(...)

Re:Writing HTML by Hand by robobro on Wednesday September 20, 2023 @08:45AM (#37583453)
Lots of references to different ways to generate html and I feel obligated to mention sexpcode, a bbcode-flavored Lisp by the same guy who came up with sleepsort. Ye Olde /prog/ used bbcode for markup and /prog/ worshiped lisp so it was a natural conclusion.

I can't see how anyone would prefer xml formatting to sexp for any significantly lengthy document. I made my own homage to sexpcode called lispmark, some of my friends find it better than markdown or html..

Re:Writing HTML by Hand by nickelcitymario on Wednesday September 20, 2023 @08:49AM (#37583498)
> Do you write HTML by hand? If so, what tags do you use most?

I like to use as many <table> and <span> tags as possible. Particularly for layouts. Sometimes, if I'm feeling frisky... <frame> gets invited to the party.

Re:Writing HTML by Hand by trilbyglens on Wednesday September 20, 2023 @08:50AM (#37583500)
Emmet!
Re:Writing HTML by Hand by zX41ZdbW on Wednesday September 20, 2023 @08:57AM (#37583556)
I write all my presentations in HTML.

Advantages: - greater flexibility than with Markdown; - no need to decide between Markdown, ReStructuredText, Wiki markup, BBCode, etc;

Disadvantages: - writing closing tags is cumbersome;

The source code is here: https://github.com/ClickHouse/clickhouse-presentations Example: https://presentations.clickhouse.com/meetup74/ai/

Re:Writing HTML by Hand by smlavine on Wednesday September 20, 2023 @06:34PM (#37591046)
> writing closing tags is cumbersome

Personally I've come to appreciate that many closing tags are unnecessary in HTML. Makes many constructs much more concise. Especially with tables:

``` <table> <caption>Some letters and numbers <thead> <tr> <th>Letters <th>Numbers <tbody> <tr> <td>A <td>1 <tr> <td>B <td>2 <tr> <td>C <td>3 </table> ```

Re:Writing HTML by Hand by erhaetherth on Thursday September 21, 2023 @03:05AM (#37594132)
Is there an HTML formatter that'll strip unnecessary closing tags?

I used to be team semi-colon in JS but I've switched teams now and have my formatter strip them. There's like 1 or 2 edge cases where that can bite you but practically speaking it's a non-issue. The real downside is that I sometimes get lazy when writing C++ and that very much dislikes poor punctuation.

Re:Writing HTML by Hand by forgotmypw17 on Wednesday September 20, 2023 @12:00PM (#37585847)
I write HTML by hand, and I am into retro-computing, so I write for Any Browser (with progressive enhancement for cooler features).

The p tag is one of the most frequent.

I use span tags for placeholders in templates, that way the HTML is still usable before it is filled in.

The tag form is important to remember, because older browsers will not even display input elements without it, and you won't be able to address them.

The font tag gets a lot of scorn these days, but it is the only compatible way to color individual parts of text in older browsers, so I use it sparingly, via templates.

There is a subset of HTML 2.0 which works consistently across about 25 years of browsers, and I think it is one of the most amazing technologies we have in the world, for its longevity, resilience, and open/unowned nature.

Re:Writing HTML by Hand by sourcecodeplz on Wednesday September 20, 2023 @01:47PM (#37587301)
Anything you don't write by hand will be difficult to replicated, by hand, later on.
Re:Writing HTML by Hand by mmphosis on Wednesday September 20, 2023 @08:07PM (#37591690)

  find . -name '*.html' -exec tags {} \; | sort | uniq -ic | sort -rh | head -n 10

  12307 td
   7224 tr
   5851 table
    950 code
    821 font
    644 a
    522 p
    373 b
    332 span
    293 br
Re:Writing HTML by Hand by wonger_ on Wednesday September 20, 2023 @11:14PM (#37592822)

    #!/usr/bin/awk -f
    BEGIN {
        while( (getline t < "tags.txt") > 0) tags[t] = 0
    }
    {
        for (t in tags) tags[t] += gsub("<" t "[ |>]", "")
    }
    END {
        for (t in tags) print tags[t], t
    }


    ./count.awk $(find . -name '\*.html') | sort -rh | head -n 10

    534 li
    290 a
    215 p
    149 br
    132 span
    99 ul
    66 b
    47 div
    40 pre
    37 meta
Lots of lists on my personal site, even excluding the one large generated page