降价元数据格式 [英] Markdown metadata format

查看:92
本文介绍了降价元数据格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在用于将元数据嵌入Markdown格式的帖子中的标准或约定,例如发布日期或帖子作者,以供渲染器进行条件渲染?

Is there a standard or convention for embedding metadata in a Markdown formatted post, such as the publication date or post author for conditional rendering by the renderer?

像这样的 Yaml元数据格式可能是它.

Looks like this Yaml metadata format might be it.

有各种各样的策略,例如随附的文件mypost.meta.edn,但我希望将其全部保存在一个文件中.

There are all kinds of strategies, e.g. an accompanying file mypost.meta.edn, but I'm hoping to keep it all in one file.

推荐答案

有两种常见的格式,它们看起来非常相似,但实际上在某些非常特定的方面有所不同.还有三分之一是非常不同的.

There are two common formats that look very similar but are actually different in some very specific ways. And a third which is very different.

Jekyll静态站点生成器普及了由 YAML部分标记定义的YAML前端问题.是的,破折号实际上是YAML语法的一部分.并且使用任何有效的YAML语法定义元数据.这是来自 Jekyll文档的示例:

The Jekyll static site generator popularized YAML front matter which is deliminated by YAML section markers. Yes, the dashes are actually part of the YAML syntax. And the metadata is defined using any valid YAML syntax. Here is an example from the Jekyll docs:

---
layout: post
title: Blogging Like a Hacker
---

请注意,YAML前端问题不是由Markdown解析器解析的,而是在由Jekyll(或您使用的任何工具)解析之前删除的,实际上可以用于请求与默认Markdown解析器不同的解析器页面(我不记得Jekyll是否这样做,但是我已经看到了一些工具).

Note that YAML front matter is not parsed by the Markdown parser, but is removed prior to parsing by Jekyll (or whatever tool you're using) and could actually be used to request a different parser than the default Markdown parser for that page (I don't recall if Jekyll does that, but I have seen some tools which do).

更老,更简单的 MultiMarkdown元数据实际上已合并到一些Markdown解析器中.尽管最近对其进行了更新以可选地支持YAML分隔符,但传统上,元数据结束,并且Markdown文档在第一行空白处开始(如果第一行为空白,则没有元数据).尽管语法看起来与YAML非常相似,但仅支持键值对,没有隐含类型.这是来自MultiMarkdown文档的示例:

The older and simpler MultiMarkdown Metadata is actually incorporated into a few Markdown parsers. While it has more recently been updated to optionally support YAML deliminators, traditionally, the metadata ends and the Markdown document begins upon the first blank line (if the first line was blank, then no metadata). And while the syntax looks very similar to YAML, only key-value pairs are supported with no implied types. Here is an example from the MultiMarkdown docs:

Title:    A Sample MultiMarkdown Document  
Author:   Fletcher T. Penney  
Date:     February 9, 2011  
Comment:  This is a comment intended to demonstrate  
          metadata that spans multiple lines, yet  
          is treated as a single value.  
CSS:      http://example.com/standard.css

MultiMarkdown解析器包括许多其他解析器独有的选项,但是键值元数据在多个解析器中使用.不幸的是,我从未见过任何两个表现完全相同的东西.没有Markdown规则定义这种格式,每个人都会做出自己略有不同的解释,从而导致多种多样.

The MultiMarkdown parser includes a bunch of additional options which are unique to that parser, but the key-value metadata is used across multiple parsers. Unfortunately, I have never seen any two which behaved exactly the same. Without the Markdown rules defining such a format everyone has done their own slightly different interpretation resulting in a lot of variety.

更常见的一件事是对YAML定义符和基本键值定义的支持.

The one thing that is more common is the support for YAML deliminators and basic key-value definitions.

为完整起见,还有 Pandoc标题栏. If具有非常不同的语法,并且不容易与其他两个语法混淆.据我所知,它仅受Pandoc支持(如果启用),并且仅支持三种类型的数据:标题,作者和日期.这是Pandoc文档中的示例:

For completeness there is also the Pandoc Title Block. If has a very different syntax and is not easily confused with the other two. To my knowledge, it is only supported by Pandoc (if enabled), and it only supports three types of data: title, author, and date. Here is an example from the Pandoc documentation:

% title
% author(s) (separated by semicolons)
% date

请注意,Pandoc标题栏是Pandoc支持的两种样式之一.如上所述,Pandoc还支持 YAML元数据.默认情况下,均未启用任何扩展名.

Note that Pandoc Title Blocks are one of two style supported by Pandoc. Pandoc also supports YAML Metadata as described above. Neither extension is enabled by default.

这篇关于降价元数据格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆