Topics
Recent articles

Developer Tools

Markdown Tilde Fence Validation

Fix a technical article validator bug that rejected valid tilde-fenced code blocks by reusing the core Markdown fence reader.

Table of Contents1 sections
Focused view of programming code displayed on a laptop, ideal for tech and coding themes.
Focused view of programming code displayed on a laptop, ideal for tech and coding themes.

Technical article quality gates frequently reject valid drafts because strict parsers fail to recognize alternative syntax. A technical draft contained seven tilde-fenced configuration or code examples, yet the quality check reported that it lacked a concrete code example because its detector looked exclusively for backticks.

Quick solution:

function hasValidCodeBlock(content: string): boolean {
  const fenceRegex = /^(?:~{3,}|`{3,})/m;
  return fenceRegex.test(content);
}

This validator implementation reuses existing rules to detect both tilde and backtick fences without adding external dependencies or new parsers.

The Markdown Dialect Disconnect

The CommonMark specification permits both backticks and tildes for enclosing code blocks. Many publishing platforms use CommonMark Spec rules for rendering while relying on custom regular expressions for internal validation checks. When a quality pipeline scans a draft for required code examples, a naive regex targeting only backticks will produce false negatives for valid tilde fences.

When building a remote publication pipeline, similar parser inconsistencies can surface across deployment environments, much like configuring an environment for Building A Remote Only Android Repository. Ensuring uniform parsing logic prevents arbitrary build failures.

Implementation Strategy

To resolve the validation gap without introducing heavy dependencies or altering storage formats, the fix must reuse the established markdown reader. Instead of writing a dedicated second parser, hook into the existing tokenization pass.

Option When to Use Trade-off or Failure Mode Recommendation
Custom Regex Check Simple keyword scanning Misses alternative valid syntaxes like tilde fences Avoid for multi-dialect documents
Shared Fence Reader Reusing production rendering parsers Slightly higher initial setup complexity Recommended for parity
Strict Backtick Policy Enforcing rigid house style Frustrates authors using nested code blocks Not recommended

Verification Checklist

Continue Exploring

You Might Also Like

View all articles
Deterministic Formatting Normalization
2 min read

Deterministic Formatting Normalization

Learn how to prevent unnecessary LLM generation retries by normalizing minor Markdown formatting variations before schema validation.

Keep Markdown Examples Out of Asset Discovery
2 min read

Keep Markdown Examples Out of Asset Discovery

Learn how to prevent automated publication asset discovery tools from mistaking literal Markdown image examples inside code blocks for real media dependencies.