Writing HTML in HTML (2019)
ankarstrom.se
ankarstrom.se
<html>
<body>
# Blog Post Title
<br>
Welcome to this simple blog post
</body>
<js>
document.body.innerHTML = document.body.innerHTML.split('<br>').map((line) => line.trim().startsWith('# ') ? `<h1>${line}</h1>` : `<p>${line.split('# ')[1]}</p>`).join(''); // add more md features here if desired
<js/>
</html>
(replace js with script, which i cant write here on hn apparently)Obviously move the JavaScript to its own file and embed it to avoid repetition across blog entries. Plus, move it into 'DOMContentLoaded' event handler to be safe.
Could it get any more elegant and beautiful?
I use Hugo and I actually prefer writing HTML over MD.
Maybe, but why do things the hard way? Even if your editor autocompletes, typing the angle brackets is more cumbersome than Markdown.
> Also remember that there are a few common elements, like <p> and <li>, that you usually don't need to close.
Having to remember random trivia like this is exactly why writing HTML is awful.
Me and some others don't find it harder. Also, what we write doesn't need a parser to output what the browser needs.
> Having to remember random trivia like this is exactly why writing HTML is awful.
Would not call it “random trivia”, these are quite basic HTML facts[1]. HTML is not XML. My theory is that some people find HTML hard to write because they make make it harder than it has to be.
[1] https://html.spec.whatwg.org/multipage/syntax.html#optional-...
If you need an editor with autocomplete to write it comfortably, that's a bigger hassle than a separate postprocessing step that can happen automatically.
> Would not call it “random trivia”, these are quite basic HTML facts[1].
It's absolutely random trivia. These particular four elements don't need closing, except this one might if it's not followed by one of this other long list of possible elements. Why would you ever know (or care about) that unless you enjoy memorizing random lists (I'll bet the reason it's those four is edge cases in a parser that someone wrote in a couple of hours 30 years ago, not any sensible logical classification), or already know the HTML spec because you work as a designer or something?
That’s how it’s worded in the spec, because that’s targeted to browser implementors, not HTML authors. To someone authoring HTML, it’s much simpler: the tag is closed by any encountered opening or closing tag that the tag is not allowed to contain. That’s nothing new to memorize, because you already have to know what elements are allowed in that context. E.g., even in XHTML served with an XML MIME type and parsed with an XML parser, <p><p></p></p> is invalid XHTML, because <p> can’t contain <p>. I already have to know that rule when writing a webpage! Knowing that <p><p> is equivalent to <p></p><p> doesn’t require higher mental overhead.
> I'll bet the reason it's those four is edge cases in a parser that someone wrote in a couple of hours 30 years ago, not any sensible logical classification
Nope, the self‐closing behavior has been present in HTML since the very beginning (inherited from SGML). As for why these elements specifically, it’s because they are among the easiest and simplest to remember due to their definition. <li> can’t contain <li>—the concept doesn’t make sense—so it makes sense for <li><li> to implicitly close the first one. <td> can’t contain <td>—the concept doesn’t make sense—so it makes sense for <td><td> to implicitly close the first one. And so on.
"It's no extra effort to memorize this piece of random trivia, because it's already implied by this other piece of random trivial that you already have to memorize" doesn't actually make it any better. I don't want to remember any of this stuff! And with Markdown I don't have to.
Just thought I'd post this "novel" idea since most people do love their MD.
<p> and <li> don’t ever need to be closed, do they? Closing would only be necessary if leaving them open would introduce ambiguity, but it never does.
Close your tags, people. Make your intent non-ambiguous. It's basic hygiene.
I honestly don't understand this level of laziness in 2023. Editors close tags automatically, ffs. For the sake of saving a keystroke or two we end up with unintuitive and ambiguous crap.
5-10 lines of VanillaJS maximum for some basic (and custom!) MD features is all I need.
<!doctype html>
<html lang=en>
<meta charset=utf-8>
<title>Hello</title>
<style>
/* css here */
</style>
<header>
<h1>Cool beanz</h1>
</header>
<nav>
<ul>
<li>Home
<li><a href=/foo.htm>Foo</a>
<li><a href=bar.htm>Bar</a>
</ul>
</nav>
<article>
<h2>The Life and Dreams of Irish Setters</h2>
<p>Widely appreciated for their qualities, the Irish Setter is a breed of dog to behold.
<p>Lorem ipsum and so on and so forth.
</article>
<footer>
<p>Copyright © 2024, Bob Schmob
</footer>
Check it :)> Document checking completed. No errors or warnings to show.
<!--#include file="/includes/header1.html" -->
The Page Title
<!--#include file="/includes/header2.html" -->
The Article Title
<!--#include file="/includes/header3.html" -->
<p>The article content</p>
<!--#include file="/includes/footer.html" -->It feels natural to me to have h1 be the site name. And have h2 be the content title. And it happens to work well when multiple unrelated articles or other kinds of content are on the page because then I use h2 for each of those.
[1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/He...
It's borderline bizarre to have watched this method of doing things kind of die out, and then also come back in the form of "static site generators" -- which, frankly, are still way clunkier than this.
Write in Zim, export to html, rsync to site. Easy.
Used to update things whenever a new ASP version was released, but haven't bothered for years.
Process is simple - copy ASP template, rename, fill in the content, FTP to hosting Co and done.
I'm not much of a programmer or designer at all, but probably my most popular thing is the "EightFiveZero" theme I made for Zim, which the author of Zim linked to from the wiki and makes me almost feel like a real programmer or something.
Also, I don't want to dump on this dude but I've authored literally hundreds of entries on my 2 blogs since 2019 using Markdown. I doubt I'd ever bother to write that many using plain HTML.
I have being doing the same for my website since ~20 years ago, where my input is mostly pure HTML, and I generate static HTML pages from those with a few scripts. My website does look rather antiquated, but I consider that a feature.
On the other hand, I've written a lot of HTML since the 90s. And there's a dirty secret behind why so many static generators exist--the effort of slapping together something that builds a site how you want it is similar to learning an existing system. Often, that's a short build script rather than some expansive framework.
Maybe I just don't like being limited by abstractions.
That’s why I like HTML for the site’s frame and markdown for the content. The amount of HTML is then finite and easy to keep correct and Markdown is harder to mess up due to its simplicity.
If I’m feeling really fancy, and the need is really there, I might add some PHP for something that needs to be done server side. It’s simple and it works.
My typical tool of choice for static sites and plain old prototyping remains Hugo, which rounds out at least half a dozen other websites I'm the sole contributor to right now, like https://hiandrewquinn.github.io/selkouutiset-archive/. Like everything you have to amortize the one time cost of learning it over the n times you use it. If you only ever make one website, raw HTML might be fine -- if you're trying to make 100, some experimentation might be worthwhile.
You will not find reasonable to reparse HTML spit out from Dreamweaver or Word to fit js/cgi parts in there but withstanding 5 years of work you may find perfectly sane to compile JSX. Plus most of the people in the field never wanted to mantain two very different stacks for work and play, it's also a good way to dogfood.
Also you can recover better in plain text when markup is messed up vs a wysiwyg editor.
Css on the other hand I hate more every day I look at it. Write some, see if it behaved as expected, it did not. Iterate until angry. There's something fundamentally wrong in my mental model for what the style text is likely to do to the appearance of the page.
A few weeks ago I decided that enough's enough. After years of writing CSS, I decided to refresh my knowledge with an intermediary level course. It turns out, a lot of stuff got mixed out, a gaps formed and grew over time.
Now, I enjoy writing CSS again as I find it more predictable and behaves as expected.
for file in .md; do pandoc --quiet --template template.html $file -o "${file%.}.html" done
just does a lil bit more ig
I‘ve been tempted a few times, as well, but it‘s a little bit too sparse for me.
The commercial app you write will last a few years before breaking. But the HTML site will last forever.
Tail end of 96 at least, even the link uses CSS. In principal you can also write JS manually within HTML.
> Client apps today have hundreds of custom features running simultaneously.
How many of those features are adverts and user-unwanted tracking that you need a GDPR compliance team for?
It makes the site look modern instantaneously.