潜入Markdown

“Sometimes the truth of a thing is not so much in the think of it, but in the feel of it.”-斯坦利库布里克

点号1

Here’s a question: When was the last time you listened to an argument, and on the basis of that argument, changed your mind? Not just about something you hadn’t really given much thought to, but something which, prior to considering the argument in question, you felt quite certain regarding your original stance.

换句话说,你最后一次意识到自己是什么时候完全错了在意见问题上?

If your answer is “never”, or even “a long time ago”, is it because you’re always right?

这是我的一个。

Back in January, there was a debate regarding the application of Postel’s Law in software that parses XML syndicated feeds (formats such asRSS原子)The nutshell synopsis is thatPostel’s Law states: “be conservative in what you do, be liberal in what you accept from others”; but theXML specification clearly states: “Once a fatal error is detected, however, the processor MUST NOT continue normal processing (i.e., it MUST NOT continue to pass character data and information about the document’s logical structure to the application in the normal way).”

So, what should software that parses XML syndicated feeds do? Follow Postel’s Law, and be liberal about errors in a feed? Or follow the XML spec, and stop processing the feed at the first fatal error?

布伦特西蒙斯(developer of NetNewsWire, the leading Mac OS syndicated newsreader) and尼克布拉德伯里(developer of FeedDemon, the leading Windows syndicated newsreader) both decided that their software would be strict when parsing Atom XML feedsMany other smart people agreed with them.

I think it’s fair to say the “clients should be strict” argument boiled down to this:

  1. 有效的,格式良好的XML比无效的XML更好。

  2. It’s not that hard to write software that produces valid, well-formed XML(或者在words of Tim Bray: “Anyone who can’t make a syndication feed that’s well-formed XML is an incompetent fool.”)

  3. 如果是领先的客户端应用程序消费XML feeds required valid and well-formed XML, it would put pressure on apps that生产提要不要生成错误的XML。

I agree with all three points, and thus, I was firmly in the “clients ought to be strict about parsing” camp.

但后来我读了Mark Pilgrim的“思想实验”Pilgrim is not just a proponent of liberal feed parsing — he’s put his code where his mouth is and written the very-well-regarded open sourceUniversal Feed Parser

Pilgrim’s key point, at least as I saw it, was this: if you’re writing software that consumes XML feeds, and your parser isn’t at least somewhat liberal, your users will suffer when they encounter a malformed feed而且,最终,您的用户encounter malformed feedsWhen that happens, the producer of the broken feed may well be at fault, but it’s the users of your software who will suffer by enforced strictness at the client end.

I read this, I engaged in his thought experiment, and I realized that I was completely wrong, and he was right(Simmons changed his mind as well; see follow-ups这里这里。)

仅仅基于他在“论证”中的论点思想实验”, Pilgrim persuaded me that I was wrongBut what’s interesting is that in doing so,he did not refute a single one of the three points that led me to side with the “be strict” camp in the first place.

因此,点号1: When I end up changing my mind on a matter of opinion, it usually isbecause I had the facts wrong; it’s because I was looking at the wrong facts.


点号2

The basic idea behind all weblog software — reduced to a nutshell — seems so simple in retrospectRather than managing a web site as a collection of网页,你管理一个集合帖子, and the weblog software takes care of turning the posts into pages for you.

博客软件对非书呆子的吸引力是显而易见的Without it, they wouldn’t be able to publish their sites.

But what’s the appeal of weblog software to nerds — HTML experts who are fully capable of hand-coding a weblog with HTML files? Sure, there are a few手工编码坚持, but for the most part, even the most懂行闻名web developers in the world are using weblogging software packages(或者他们已经written their own出版软件。)

答案是方便和灵活Weblog software takes away an inordinate amount of the monotony involved with updating a web siteI must profess — I personally didn’t figure this out until 2002, a few months before I launched 万博manbetx贴吧The fact that I was capable of hand-coding an entire web site — and in fact considered hand-coding简单— blinded me to the fact that it involved an awful lot of repetitive monkey work.

这是每次我发布新文章到万博manbetx贴纸时发生的事情:

  1. The new post appears at the top of the home page (and the oldest post on the home page is removed).
  2. 新帖子在页面上获得永久的主页。
  3. 我的RSS源已使用新帖子进行更新。
  4. 标题和新页面的链接将添加到我的档案页。
  5. The title and a link to the new page are added as a “Next entry” pointer on the page for the previous entry.

I take just one action — posting a new article — and Movable Type creates one new file and updates four othersNone of these tasks would be手工完成Mostly, it’d be a copy-and-paste jobBut it sure would be monotonous — and even though it admittedly would not be, there would still be a high chance I’d make mistakesI’d make them because I’d get bored or simply forget to perform one of the stepsMonotonous repetitive tasks are exactly what computers are good at, and what humans are bad at.

此外,封装感觉自然Writing a new article — or making changes to an existing one —感觉like it ought to be one taskIt’s the article I want to edit, not the individual pages where it appears.

因此,点号2: Just because something isn’t difficult doesn’t mean it’s the way it ought to be done.


在哪里我尝试联合点数1和2为Markdown制作案例

我们退一步吧Above, I wrote that weblog software allows you to manage a web site as a collection of posts instead of pages.

但那是什么呢岗位

传统观点认为帖子是HTML的片段Not a full HTML document, just a snippet of HTML-formatted text — the weblog software takes care of forming full HTML (and/or XML) documentsYour weblog templates contain all the tags related to document structure —<HTML><HEAD><BODY>等等— and they have slots for where your posts will goWhen you publish, your weblog software takes your posts, as snippets of HTML, and plugs them into your HTML templates.

For the full first year I published 万博manbetx贴吧, from August 2002 to around August of last year, I was perfectly happy to buy into this post-as-snippet-of-HTML conceptI never really even considered an alternativeEverything I wrote for 万博manbetx贴吧, I wrote formatted as valid HTML(其实XHTML, but the difference is irrelevant here.)

当然,除了片段of HTML can’t be validated, because HTML is a文献格式你可以写合式snippets of HTML — making sure you close all your tags and escape all your ampersands and angle brackets — but you can’t pass a snippet of HTML to theW3C HTML Validator, nor can you pass it through BBEdit’s HTML syntax checker.

我的工作流程:

  1. 在BBEdit中编写,编辑和修改。
  2. When it’s ready, log into MT’s web interface, paste the article, and publish.

但我的实际工作流程看起来像这样:

  1. 写在BBEdit。
  2. 在浏览器中预览。
  3. 切换回BBEdit进行修订。
  4. 重复直到完成。
  5. 登录MT,粘贴文章,发布。

最终,我突然意识到:这太疯狂了The primary advantage to using a computer for writing is the immediacy of editingWrite, read, revise, all in the same window, all in the same mode.

争论对于writing text in raw HTML — the argument I used myself for years — is that HTML is not hard.I still agree with this.HTML is pretty easy to learn, and once learned, easy to apply. Full-blown web development? That’s hardBut the basic tags and rules of HTML — enough HTML to be capable of composing weblog entries in raw HTML — that’s easy.

但是纯文本浏览器喜欢的原因就在于此山猫don’t just show you the raw HTML source codeIt’s simply not meant to be a readable formatDoesn’t it strike you as odd to write in a format that isn’t readable? Suddenly, it struck me as absurd.

点数的应用1:我不是在争论原始HTML很难I agree that it’s easyI’m arguing an orthogonal point — that what it’s easy for is tagging a document with markup,reading and composing prose.

点数的应用2: Even if you insist that it’s easy to compose text in raw HTML, isn’t it a chore? Isn’t it tedious to write “AT&amp; T公司“而不只是”AT&T”? (Not to mention the necessity of encoding ampersands within URLs?)

这是2004年Shouldn’t your computer be able to determine where you’ve written paragraphs and sub-heads?

And don’t tell me that Movable Type’s “Convert Line Breaks” feature does that for youMT 2.661’s “Convert Line Breaks” will turn these two lines of input:

<h2>This is a header.</h2>

This is a paragraph.

进入这个:

<p><h2>This is a header.</h2></p>

<p>This is a paragraph.</p>

这真是太傻了TypePad is apparently smart enough not to wrap spurious<P>tags around block-level HTML tags — so MT 3.0 probably will be too — but it still doesn’t alleviate any of the other tedium or visual clutter of raw HTML.

Why is it that desktop weblog editors need to provide “preview” modes? You don’t need to “preview” an email before you send it — you write it, you read it, you edit it, right there.

事实上,我喜欢写电子邮件Email is my favorite writing medium. I’ve sent over 16,000 emails in the last five yearsThe conventions of plain text email allow me to express myself clearly and precisely, without ever getting in my way.

因此,Markdown电子邮件式的网络写作。

Most other text-to-HTML filters are based on the premise that HTML tags are difficult, and so they go out of their way to replace HTML tags with their own, which end up being neither “easier” nor more readable than HTMLAnd at the same time, they end up making it hard to drop into manual and just use raw HTML when you really need to.

其他过滤器旨在取代HTMLMarkdown is aimed elsewhereIt’s aimed at a sweet spot, between making it easy to use real HTML when you need it, and letting you just write plain text for anything where it’s sensible and obvious to do so.

The tags that most weblog apps provide shortcuts for — italics, bold, links, paragraphs, blockquotes — are the ones you shouldn’t need to worry about “tagging” in the first placeMaking it easy to insert these tags does nothing to make it easier to write, and worse, makes your composition harder to read.

But when you do need to use inline raw HTML — say, to create a specially-formatted ordered list using custom class attributes — you ought to be able to just drop into HTMLNo escapes, no special mode-switching markers, just use the tagsMarkdown lets you do this, because it’s designed specifically and only as a pre-processor for HTML.

(If you really do want to translate a Markdown-formatted document to some non-HTML format, just translate it to HTML first, then use an existing HTML-to-whatever filter.)

And while I do think HTML is easy, there’s one particular area where it is in fact quite tricky, if not downright difficult: using HTML markup to write关于HTML标记是屁股的主要痛苦When you write about code, you should only have to worry about the example code itself — not about escaping every single instance of<&LT;&安培;

In addition to making it easy to include inline HTML tags in a document, Markdown also makes it easy to includeHTML tags within code spans and code blocks.

感觉vs认为

The typographic constraints of plain text — a single typeface, in a single size, with no true italics or bold — are very much similar to the constraints of a typewriterImagine that someone was nice enough to buy you a gift: an original typewritten manuscript for a classic novel让我们说菲茨杰拉德的“了不起的盖茨比”You could sit down with this manuscript and read it, straight through, and get pretty much the same reading experience as you would when reading it in the form of a nicely bound and typeset bookYes, it would all be set in the typewriter’s smudgy fixed-width Courier-esque typeface, with underlining instead of italics, etc— but the words would still flow, from page to mind, just as Fitzgerald intended.

The quote from Stanley Kubrick I used to start this article is one of my very favoritesWhen you write and read text that’s marked-up with HTML tags, it’s forcing you to concentrate on the想一想It’s the感觉它我希望Markdown格式的文本传达。