from Hacker News

Writing HTML in HTML (2019)

by blakewatson on 1/12/24, 3:07 AM with 68 comments

  • by jdthedisciple on 1/14/24, 6:08 PM

    Here is a better solution: You write your blog post md directly into the body and deploy a builtin minimal md engine.

        <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?

  • by jrm4 on 1/14/24, 7:05 PM

    It is so hard not to feel REALLY SMUG reading stuff like this, as someone who has run my own website as the working primary source for my college instruction for the past 15 years or so using https://zim-wiki.org. (before Markdown was much of a thing!)

    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.

  • by gerikson on 1/14/24, 5:23 PM

    Updated post from 2020: https://ankarstrom.se/~john/articles/html2/

    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.

  • by Semiapies on 1/14/24, 5:51 PM

    On the one hand, I think everyone should try to put together a simple website with a few pages in raw HTML, just to get an idea of how it works. And actual, semantic HTML is not terrible in this day and age, much better than it used to be. You don't have to learn a static generator to put up a website, because you're the static generator.

    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.

  • by CM30 on 1/14/24, 7:23 PM

    I'm not sure I agree that HTML is unpleasant to write. Honestly, even when I'm writing blog posts or articles, I often fall back to writing the HTML myself. It feels about as simple/complex as writing markdown, or using a WYSIWYG editor.

    Maybe I just don't like being limited by abstractions.

  • by hiAndrewQuinn on 1/14/24, 7:03 PM

    When I remember to update https://build-100-websites.fun/ with my recent antics (whew it's been a while), I like to write it in raw HTML just so I remember why I never ever do that anywhere else.

    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.

  • by yladiz on 1/15/24, 5:06 AM

    I did this for a time and had attempted to commit to staying “no build tools” but after writing a few blog posts and needing to move content of the post around as I was writing it, I gave up the masochism. I do think that it’s important to know HTML as a web developer, and to get your feet wet sometimes, but unless you’re really able to deal with the genuine annoyance of writing only HTML and are doing it for puritanical reasons I don’t think there’s any real reason not to use a tool, especially if you plan to add things to your website.
  • by ulrischa on 1/14/24, 7:20 PM

    Dreamweaver was perfect for this. It has templates and libraries and you wrote in a split editor with html and wysiwyg. Why was it abandoned by many web developers?
  • by JonChesterfield on 1/14/24, 9:32 PM

    I'm really liking writing HTML in markdown. Write the markdown, feed it to commonmark's parser, splice the text together in ad hoc sorts of ways. Robust, trivial.

    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.

  • by malkosta on 1/14/24, 8:26 PM

    I stopped looking at SSGs after this:

    for file in .md; do pandoc --quiet --template template.html $file -o "${file%.}.html" done

  • by foul on 1/14/24, 11:49 PM

    You guys trying to revive the FrontPage/Dreamweaver era?
  • by proc0 on 1/12/24, 4:23 AM

    Sure, when your site looks like it's from 1995. Client apps today have hundreds of custom features running simultaneously.