Show HN:Typeform 替代方案,将 Markdown 转换为表单
Show HN: Typeform alternative, turns Markdown to forms

原始链接: https://blocks.md

使用配对 ::: 将内容包裹在

标记之间。 任何有效的 Markdown 内容(如标题、段落、列表、表单等)都是可接受的。 可以通过[...]添加其他类和属性(上面进一步解释)。 此外,通过将多个字段的名称括在 [...] 内的大括号 ($...$) 中,将多个字段分配给
元素,从而在绑定字段值更改时启用自动更新。 利用 Nunjucks 进行模板化可以支持 if-else 语句、循环、过滤器等结构。 此外,可以使用 {$ field $} 将单个字段分配给 标记。 虽然通用性较差,但这简化了段落、标题、列表项等区域的使用。 以下是使用选择框、数字输入和 span 元素的示例: ``降价 [.col-4] 已选择:{$产品$} ::: [.col-8 .text-end .xs:text-start {$价格数量$}] {% 如果价格和数量 -%} 合计:${{ 价格 }} × {{ 数量 }} = ${{ 价格 * 数量 }} {% 别的 -%} 总计:设定价格和数量 {% 结束 %} ::: ````` 在此示例中,我们创建两个输入字段“产品”和“价格”。 通过将它们绑定到特定部分,更新这些字段将导致相关部分自动刷新。 例如,更改产品选择将更新“所选”部分,而调整“价格”或“数量”输入将重新计算“总计”部分下显示的总成本。 该示例使用以下数据结构: ```javascript SelectBox({问题: '产品', 选项: ['T 恤', '袜子'], 选择: 'T 恤'}, NumberInput({问题:'价格',unitEnd:'$',子字段:true}, NumberInput({问题: '数量', 子字​​段: true}) ) ````` 此外,单个字段可以绑定到 元素,这在整个文档的各种上下文中都很有用。

用户正在讨论 GitHub 上名为“BlocksMD”的软件的许可证。 许可证于 2028 年 7 月 1 日从 Business Source License 1.1 更改为 Affero General Public License (AGPL)-3.0。但是,用户觉得很奇怪,因为与 BSL 相比,AGPL 是一个限制性更强的许可证,特别是对于那些不打算这样做的人 开发竞争产品。 用户提到他们计划暂时使用该软件,但如果他们根据 AGPL 要求更新到 2028 年之后的最新版本,则需要开源整个软件堆栈。 此外,用户指出,随着他们转向更高级的功能,他们发现 BlocksMD 使用的领域特定语言 (DSL) 变得越来越笨拙。 用户建议为更复杂的用途提供 JavaScript XML 模板库 (JSX/TSX) 替代方案。 最后,用户指出 DSL 的名称和美观并不吸引人,并建议进行更改。 概括: 用户讨论了他们对 BlocksMD 许可的困惑,该软件是他们在 GitHub 上发现的软件,该软件于 2028 年 7 月 1 日过渡到更严格的许可证 (Affero 通用公共许可证 3.0)。用户计划暂时使用该软件,但必须 如果根据 AGPL 规定,他们选择更新到 2028 年后的最新版本,则将其完整的软件堆栈开源。 此外,当用户探索更复杂的功能时,用户批评了 BlocksMD DSL 的复杂性,并建议实施 JavaScript XML 模板库替代方案。 最后,用户对BlocksMD的命名和外观表示不满。
相关文章

原文

Create wrapping <div> elements by putting content inside pairs of :::. The content inside can be any valid Markdown, such as headings, paragraphs, lists, form fields, etc. Class names and other attributes are supported via [...] (see above). Moreover, you can bind one or more fields to a <div> element by adding the names of the fields inside {$...$} (separated by spaces), and placing this within the [...]. This means that whenever the value of a binded field changes, the content inside the <div> will be automatically re-rendered.

The templating is done using Nunjucks, so its entire list of features such as if-else statements, loops, filters, etc. are fully supported. You can also bind a single field to a <span> element using {$ field $}. This is obviously not as flexible, but it is simple, and can be used inside paragraphs, headings, list items, etc.

Further reading: Data-binding - Docs

Markdown

product* = SelectBox(
	| question = Product | options = T-Shirts, Socks 
	| selected = T-Shirts | subfield
)

price* = NumberInput(
	| question = Price | unitEnd = $ | subfield | min = 1
)

quantity* = NumberInput(
	| question = Quantity | subfield | min = 1
)

[.col-4]
Selected: {$ product $}

::: [.col-8 .text-end .xs:text-start {$ price quantity $}]
{% if price and quantity -%}
	Total: ${{ price }} × {{ quantity }} = ${{ price * quantity }}
{% else -%}
	Total: Set price and quantity
{% endif %}
:::
联系我们 contact @ memedata.com