subtitles_in_markdown
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| subtitles_in_markdown [2026/04/25 19:03] – smickster | subtitles_in_markdown [2026/04/25 19:09] (current) – smickster | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| This page defines a **strict syntax specification** for a custom Markdown-like subtitle source format. | This page defines a **strict syntax specification** for a custom Markdown-like subtitle source format. | ||
| It is designed so you can write subtitles in plain text, then reliably parse and convert them to SRT, WebVTT, ASS, or other formats. | It is designed so you can write subtitles in plain text, then reliably parse and convert them to SRT, WebVTT, ASS, or other formats. | ||
| + | |||
| + | **Spec version**: 1.1 \\ | ||
| + | **Last updated**: 2025 \\ | ||
| + | **Status**: Draft | ||
| ===== Technical Overview ===== | ===== Technical Overview ===== | ||
| - | **Format name**: MDSub Custom (inspired by mdsub and similar tools) \\ | + | **Format name**: MDSub Custom (inspired by [[https:// |
| **Purpose**: | **Purpose**: | ||
| **Target outputs**: SRT, WebVTT, ASS/SSA \\ | **Target outputs**: SRT, WebVTT, ASS/SSA \\ | ||
| - | **Parser requirements**: | + | **Parser requirements**: |
| + | **Character encoding**: UTF-8 without BOM (see [[# | ||
| + | |||
| + | ===== Output Format Comparison ===== | ||
| + | |||
| + | Before choosing a target format, use this table to pick the right one for your use case. | ||
| + | |||
| + | ^ Feature ^ SRT ^ WebVTT ^ ASS/SSA ^ | ||
| + | | Browser native support | Limited | Yes (HTML5) | No | | ||
| + | | Styling support | None | Basic (CSS) | Full | | ||
| + | | Positioning control | No | Yes | Yes | | ||
| + | | Right-to-left text | Poor | Yes | Yes | | ||
| + | | Player support | Universal | Modern browsers | Aegisub, MPC, VLC | | ||
| + | | File simplicity | Highest | High | Low | | ||
| + | | Best used for | General distribution | Web video | Fansubs, styled video | | ||
| ===== Strict Syntax Rules ===== | ===== Strict Syntax Rules ===== | ||
| Line 18: | Line 36: | ||
| * Timestamps use ISO-like format: '' | * Timestamps use ISO-like format: '' | ||
| * Each cue = 1 timestamp line + 1-3 text lines | * Each cue = 1 timestamp line + 1-3 text lines | ||
| - | * Blank lines separate cues | + | * Blank lines separate cues — the blank line is the cue terminator, not optional whitespace |
| - | * Comments use ''//'' | + | * Comments use '' |
| * File must start with optional metadata header | * File must start with optional metadata header | ||
| + | * Files must be saved as UTF-8 without BOM | ||
| ===== Complete Line Types ===== | ===== Complete Line Types ===== | ||
| ^ Type ^ Pattern ^ Example ^ Parser Action ^ | ^ Type ^ Pattern ^ Example ^ Parser Action ^ | ||
| - | | Metadata | ''// | + | | Metadata | '' |
| - | | Metadata | ''// | + | | Metadata | '' |
| - | | Comment | ''// | + | | Comment | '' |
| | Timestamp | '' | | Timestamp | '' | ||
| | Speaker | '' | | Speaker | '' | ||
| | Dialogue | Plain text | '' | | Dialogue | Plain text | '' | ||
| - | | Emphasis | '' | + | | Emphasis | '' |
| - | | Style | ''<< | + | | Style | '' |
| | Empty | (blank line) | — | End current cue | | | Empty | (blank line) | — | End current cue | | ||
| ===== File Structure ===== | ===== File Structure ===== | ||
| + | |||
| + | The blank line between cues is structural — the parser uses it as the signal to finalize | ||
| + | and store the current cue. A missing blank line will cause two cues to merge incorrectly. | ||
| < | < | ||
| - | // Optional metadata block | + | // Title: Example File |
| + | // Language: en-US | ||
| [00: | [00: | ||
| Line 55: | Line 78: | ||
| **Format**: '' | **Format**: '' | ||
| + | |||
| + | **Capture groups in the parser regex** (groups 1–4 = start time, groups 5–8 = end time): | ||
| + | - Hours (start) | ||
| + | - Minutes (start) | ||
| + | - Seconds (start) | ||
| + | - Milliseconds (start) | ||
| + | - Hours (end) | ||
| + | - Minutes (end) | ||
| + | - Seconds (end) | ||
| + | - Milliseconds (end) | ||
| **Validation rules**: | **Validation rules**: | ||
| Line 66: | Line 99: | ||
| < | < | ||
| - | ^\s*(\d{2}): | + | ^\[\s*(\d{2}): |
| </ | </ | ||
| Line 72: | Line 105: | ||
| **State: IDLE** | **State: IDLE** | ||
| - | * Metadata line (''//'' | + | * Metadata line ('' |
| * Timestamp line → Create new Cue, go to COLLECTING | * Timestamp line → Create new Cue, go to COLLECTING | ||
| * Other → Error | * Other → Error | ||
| Line 85: | Line 118: | ||
| ==== SRT ==== | ==== SRT ==== | ||
| + | |||
| + | Note: SRT uses a comma as the millisecond separator, not a period. This is a common | ||
| + | source of bugs when converting from other formats. | ||
| < | < | ||
| Line 104: | Line 140: | ||
| ==== ASS ==== | ==== ASS ==== | ||
| + | |||
| + | ASS is the most complex output format. The '' | ||
| + | using pixel coordinates. For a 1280×720 canvas, center-bottom is roughly '' | ||
| + | The coordinate origin is top-left. ASS requires a full '' | ||
| + | header in real files — what is shown below is the Events section only. | ||
| < | < | ||
| Line 110: | Line 151: | ||
| Dialogue: 0, | Dialogue: 0, | ||
| </ | </ | ||
| + | |||
| + | For full ASS file structure reference, see: [[https:// | ||
| ===== Markdown Processing Rules ===== | ===== Markdown Processing Rules ===== | ||
| Line 118: | Line 161: | ||
| | '' | | '' | ||
| | '' | | '' | ||
| + | |||
| + | Note: SRT does not support inline styling in most players. Bold and italic markers are | ||
| + | passed through as literal text for SRT output since behaviour varies by player. | ||
| ===== Complete Parser Pseudocode ===== | ===== Complete Parser Pseudocode ===== | ||
| Line 163: | Line 209: | ||
| ===== Validation Checklist ===== | ===== Validation Checklist ===== | ||
| - | Before | + | Run these checks before |
| + | how to handle each failure. | ||
| - | * All timestamps parse correctly | + | * All timestamps parse correctly |
| - | * End time > start time for each cue | + | * End time > start time for every cue |
| - | * No overlapping timestamps | + | * No overlapping timestamps |
| - | * Maximum 2 lines per cue (SRT limit) | + | * Maximum 2 lines of dialogue |
| - | * Maximum 42 characters per line (SRT recommendation) | + | * Maximum 42 characters per line (SRT recommendation |
| - | * Consistent language metadata | + | * Consistent language metadata |
| + | * File is UTF-8 encoded without BOM | ||
| ===== Error Conditions ===== | ===== Error Conditions ===== | ||
| Line 178: | Line 226: | ||
| | Overlapping cues | '' | | Overlapping cues | '' | ||
| | Empty cue text | '' | | Empty cue text | '' | ||
| - | | Unclosed cue | '' | + | | Unclosed cue at EOF | '' |
| + | | BOM detected | '' | ||
| + | | Encoding error | '' | ||
| + | |||
| + | ===== Known Limitations and Edge Cases ===== | ||
| + | |||
| + | These are areas where the format or its parser may behave unexpectedly. Test these | ||
| + | cases before deploying in production. | ||
| + | |||
| + | ==== Right-to-Left Text ==== | ||
| + | |||
| + | RTL languages (Arabic, Hebrew, Persian) require Unicode bidi control characters for | ||
| + | correct display. This format passes text through as-is; bidi rendering is the | ||
| + | responsibility of the player or browser. WebVTT and ASS handle RTL significantly | ||
| + | better than SRT. | ||
| + | |||
| + | ==== Overlapping Cues ==== | ||
| + | |||
| + | The spec recovers overlapping cues by using the earliest end time, but many players | ||
| + | handle overlapping SRT cues differently — some show both, some show only the first, | ||
| + | some show neither. For WebVTT, overlapping cues are valid by spec. For SRT, avoid | ||
| + | overlaps entirely if broad player compatibility is needed. | ||
| + | |||
| + | ==== The 42-Character Line Limit ==== | ||
| + | |||
| + | This is a guideline from broadcast subtitle conventions, | ||
| + | Many desktop players ignore it entirely. However, streaming platforms (Netflix, YouTube | ||
| + | auto-import) may reject or reformat SRT files that exceed it. Treat it as a hard limit | ||
| + | if you're targeting platform upload. | ||
| + | |||
| + | ==== Multi-Line Cue Behaviour ==== | ||
| + | |||
| + | The spec allows 1–3 text lines per cue, but SRT players typically display a maximum | ||
| + | of 2 lines reliably. A third line may be hidden below the frame on some players. | ||
| + | Limit to 2 lines for safest cross-player compatibility. | ||
| + | |||
| + | ==== Millisecond Precision ==== | ||
| + | |||
| + | SRT officially supports milliseconds (3 digits). Some legacy SRT players only parse | ||
| + | 2-digit centiseconds. If targeting very old hardware players, consider rounding to | ||
| + | centisecond precision in your SRT output. | ||
| + | |||
| + | ==== Encoding and Character Set Notes ==== | ||
| + | |||
| + | * Always save as **UTF-8 without BOM** | ||
| + | * UTF-8 with BOM will break most SRT parsers (the BOM appears as garbage at the start of cue 1) | ||
| + | * WebVTT requires UTF-8 by specification | ||
| + | * ASS files traditionally use UTF-8 or local codepage — Aegisub defaults to UTF-8 | ||
| + | * Special characters like em-dash (—), ellipsis (…), and curly quotes should be used | ||
| + | as Unicode codepoints, not HTML entities, in the source format | ||
| ===== Implementation Notes ===== | ===== Implementation Notes ===== | ||
| Line 186: | Line 283: | ||
| **Runtime**: | **Runtime**: | ||
| **File size limit**: 10MB source → ~1M cues \\ | **File size limit**: 10MB source → ~1M cues \\ | ||
| - | **Output validation**: | + | **Output validation**: |
| - | ===== Sample Implementation Links ===== | + | ===== Related Tools and Ecosystem |
| - | //(Add your own scripts here)// | + | These are the standard tools you are likely to use alongside this format. |
| - | * Python converter: '' | + | |
| - | * Node.js version: '' | + | ==== Subtitle Editors ==== |
| - | * Test files: '' | + | |
| + | * [[https://aegisub.org/|Aegisub]] — The standard open-source editor for ASS/SSA. Also handles SRT and WebVTT import/ | ||
| + | * [[https:// | ||
| + | |||
| + | ==== Conversion and Processing ==== | ||
| + | |||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | |||
| + | ==== Validation ==== | ||
| + | |||
| + | * [[https:// | ||
| + | * VLC Media Player — Reliable real-world test for SRT and WebVTT rendering. Drag subtitle file onto playing video. | ||
| + | * Firefox DevTools — Open a local HTML5 video with a '' | ||
| + | |||
| + | ==== Reference Specifications ==== | ||
| + | |||
| + | * [[https://www.w3.org/ | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | |||
| + | ==== Related Pages (this wiki) ==== | ||
| + | |||
| + | * [[fountain_syntax|Fountain: | ||
| ===== Quick Implementation Template ===== | ===== Quick Implementation Template ===== | ||
| Line 199: | Line 320: | ||
| <code python> | <code python> | ||
| # | # | ||
| + | # mdsub2srt.py — minimal MDSub to SRT converter | ||
| import re | import re | ||
| import sys | import sys | ||
| - | TIMESTAMP_RE = re.compile(r' | + | TIMESTAMP_RE = re.compile( |
| + | | ||
| + | ) | ||
| def parse_mdsub(filename): | def parse_mdsub(filename): | ||
| # Implementation here following spec above | # Implementation here following spec above | ||
| + | pass | ||
| + | |||
| + | def print_srt(cues): | ||
| + | # Implementation here | ||
| pass | pass | ||
| if __name__ == " | if __name__ == " | ||
| + | if len(sys.argv) < 2: | ||
| + | print(" | ||
| + | sys.exit(1) | ||
| cues = parse_mdsub(sys.argv[1]) | cues = parse_mdsub(sys.argv[1]) | ||
| print_srt(cues) | print_srt(cues) | ||
| </ | </ | ||
| + | |||
| + | ===== Sample Implementation Links ===== | ||
| + | |||
| + | * Python converter: '' | ||
| + | * Node.js version: '' | ||
| + | * Test files: '' | ||
| ===== Final Notes ===== | ===== Final Notes ===== | ||
| - | This spec is complete and deterministic. | + | This spec is complete and deterministic. Any implementation following these rules will |
| - | Any implementation following these rules will produce identical output from the same source file. | + | produce identical output from the same source file. |
| - | Test thoroughly with edge cases before production use. | + | |
| + | The format intentionally omits production features like cue numbering (handled on output), | ||
| + | revision marks, and locked timecodes. It is designed for the authoring phase — once | ||
| + | converted to SRT/ | ||
| + | |||
| + | Test thoroughly with edge cases — particularly encoding, overlapping cues, and RTL text — | ||
| + | before production use. | ||
subtitles_in_markdown.1777143833.txt.gz · Last modified: by smickster
