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 18:49] – smickster | subtitles_in_markdown [2026/04/25 19:09] (current) – smickster | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== |
| - | This page collects the main ideas behind writing screenplays | + | This page defines a **strict syntax specification** for a custom Markdown-like subtitle source format. |
| + | It is designed so you can write subtitles | ||
| - | ===== Overview ===== | + | **Spec version**: 1.1 \\ |
| + | **Last updated**: 2025 \\ | ||
| + | **Status**: Draft | ||
| - | Fountain is a plain-text screenplay format. | + | ===== Technical Overview ===== |
| - | It is designed so you can write a script in any text editor and later convert it into properly formatted screenplay output. | + | |
| - | A markdown-style screenplay workflow is similar | + | **Format name**: MDSub Custom (inspired by [[https:// |
| + | **Purpose**: | ||
| + | **Target outputs**: SRT, WebVTT, ASS/SSA \\ | ||
| + | **Parser requirements**: | ||
| + | **Character encoding**: UTF-8 without BOM (see [[# | ||
| - | ===== Why use plain text? ===== | + | ===== Output Format Comparison |
| - | Plain text writing is useful because it is: | + | Before choosing a target format, use this table to pick the right one for your use case. |
| - | * Portable. | + | ^ Feature ^ SRT ^ WebVTT ^ ASS/SSA ^ |
| - | * Easy to edit in any text editor. | + | | Browser native support | Limited | Yes (HTML5) | No | |
| - | * Friendly to version | + | | Styling support | None | Basic (CSS) | Full | |
| - | * Easy to automate or convert later. | + | | Positioning |
| - | * Less dependent on one specific app. | + | | 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 | | ||
| - | ===== Core screenplay elements | + | ===== Strict Syntax Rules ===== |
| - | A screenplay usually includes | + | Every subtitle file MUST follow |
| - | * Title page. | + | * Lines are processed sequentially — no lookahead beyond current line |
| - | * Scene headings. | + | * Timestamps use ISO-like format: '' |
| - | * Action | + | * Each cue = 1 timestamp line + 1-3 text lines |
| - | * Character names. | + | * Blank lines separate cues — the blank line is the cue terminator, not optional whitespace |
| - | * Dialogue. | + | * Comments use '' |
| - | * Parentheticals. | + | * File must start with optional metadata header |
| - | * Transitions. | + | * Files must be saved as UTF-8 without BOM |
| - | * Optional notes or annotations. | + | |
| - | ===== Fountain-style examples | + | ===== Complete Line Types ===== |
| - | Below is a simple example showing the main screenplay parts in Fountain-like plain text. | + | ^ Type ^ Pattern ^ Example ^ Parser Action ^ |
| + | | Metadata | '' | ||
| + | | Metadata | '' | ||
| + | | Comment | '' | ||
| + | | Timestamp | '' | ||
| + | | Speaker | '' | ||
| + | | Dialogue | Plain text | '' | ||
| + | | Emphasis | '' | ||
| + | | Style | '' | ||
| + | | Empty | (blank line) | — | End current cue | | ||
| + | |||
| + | ===== 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. | ||
| < | < | ||
| - | Title: | + | // Title: |
| + | // Language: en-US | ||
| - | INT. KITCHEN | + | [00:00:01.000 --> 00: |
| + | [NARRATOR] | ||
| + | Welcome to the show. | ||
| - | A quiet kitchen. Sunlight comes through | + | [00:00:03.500 --> 00: |
| + | This is the first subtitle. | ||
| - | JORDAN | + | [00: |
| - | I thought | + | [JANE] |
| + | Whispering: Did you hear that? | ||
| + | </ | ||
| - | MAYA | + | ===== Timestamp Specification ===== |
| - | I was. Then I changed my mind. | + | |
| - | (Jordan sets down the cup.) | + | **Format**: '' |
| - | CUT TO: | + | **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) | ||
| - | EXT. STREET | + | **Validation rules**: |
| + | * Hours: '' | ||
| + | * Minutes/ | ||
| + | * Milliseconds: | ||
| + | * End time must be greater than start time | ||
| + | * Leading zeros required | ||
| - | Cars pass by as they walk toward the corner. | + | **Parser regex** (PCRE compatible): |
| + | |||
| + | < | ||
| + | ^\[\s*(\d{2}): | ||
| </ | </ | ||
| - | ===== What the parts mean ===== | + | ===== Parser State Machine |
| - | ==== Title page ==== | + | **State: IDLE** |
| + | * Metadata line ('' | ||
| + | * Timestamp line → Create new Cue, go to COLLECTING | ||
| + | * Other → Error | ||
| - | The title page identifies the script. | + | **State: COLLECTING** |
| - | In a plain-text workflow, this may be handled by the file name, a metadata block, or a separate front matter section. | + | * Blank line → Finalize cue, go to IDLE |
| + | * Speaker line → Set cue.speaker, stay COLLECTING | ||
| + | * Dialogue line → Append to cue.text, stay COLLECTING | ||
| + | * Timestamp → Finalize current cue, create new cue, stay COLLECTING | ||
| - | ==== Scene heading | + | ===== Output Format Mappings ===== |
| - | A scene heading tells us where and when the scene happens. | + | ==== SRT ==== |
| - | Example: | + | Note: SRT uses a comma as the millisecond separator, not a period. This is a common |
| + | source of bugs when converting from other formats. | ||
| < | < | ||
| - | INT. OFFICE | + | 1 |
| + | 00: | ||
| + | [NARRATOR] | ||
| + | Welcome to the show. | ||
| </ | </ | ||
| - | Common parts: | + | ==== WebVTT ==== |
| - | * INT. or EXT. | + | < |
| - | * Location. | + | WEBVTT |
| - | * Time of day. | + | |
| - | ==== Action line ==== | + | 00: |
| + | [NARRATOR] | ||
| + | Welcome to the show. | ||
| + | </ | ||
| - | Action lines describe what is happening visually. | + | ==== ASS ==== |
| - | Example: | + | 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. | ||
| < | < | ||
| - | The door opens slowly. | + | [Events] |
| + | Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text | ||
| + | Dialogue: 0, | ||
| </ | </ | ||
| - | Keep action lines clear and present tense. | + | For full ASS file structure reference, see: [[https:// |
| - | ==== Character name ==== | + | ===== Markdown Processing Rules ===== |
| - | The character name appears before dialogue. | + | ^ Source ^ SRT ^ WebVTT ^ ASS ^ |
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| - | Example: | + | 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 ===== |
| - | ALEX | + | |
| - | </ | + | |
| - | Usually this is centered or visually separated in screenplay output, even though in plain text it is just a line of text. | + | <code javascript> |
| + | function parseMDSub(source) { | ||
| + | let cues = []; | ||
| + | let currentCue = null; | ||
| + | let metadata = {}; | ||
| - | ==== Dialogue ==== | + | for (let line of source.split(' |
| + | line = line.trim(); | ||
| - | Dialogue is the spoken text under the character name. | + | if (line.startsWith('//' |
| + | parseMetadata(line, | ||
| + | continue; | ||
| + | } | ||
| - | Example: | + | if (isTimestampLine(line)) { |
| + | if (currentCue) finalizeCue(currentCue, | ||
| + | currentCue = newCue(parseTimestamp(line)); | ||
| + | continue; | ||
| + | } | ||
| - | < | + | if (line === '' |
| - | ALEX | + | if (currentCue) finalizeCue(currentCue, |
| - | We should leave now. | + | |
| - | </ | + | |
| + | } | ||
| - | In many plain-text formats, the structure is implied by spacing and line order. | + | if (currentCue) { |
| + | if (isSpeakerLine(line)) { | ||
| + | currentCue.speaker = extractSpeaker(line); | ||
| + | } else { | ||
| + | currentCue.text.push(processMarkdown(line)); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| - | ==== Parenthetical ==== | + | if (currentCue) finalizeCue(currentCue, |
| + | return { metadata, cues }; | ||
| + | } | ||
| + | </ | ||
| - | Parentheticals give a small direction about how the line is delivered. | + | ===== Validation Checklist ===== |
| - | Example: | + | Run these checks before conversion. See [[# |
| + | how to handle each failure. | ||
| - | <code> | + | * All timestamps parse correctly against the regex |
| - | ALEX | + | * End time > start time for every cue |
| - | (quietly) | + | * No overlapping timestamps between consecutive cues |
| - | We should leave now. | + | * Maximum 2 lines of dialogue per cue (SRT hard limit in many players) |
| - | </ | + | * Maximum 42 characters per line (SRT recommendation — not enforced by all players) |
| + | * Consistent language metadata declared at top of file | ||
| + | * File is UTF-8 encoded without BOM | ||
| - | Use parentheticals sparingly. | + | ===== Error Conditions ===== |
| - | ==== Transition ==== | + | ^ Error ^ Message ^ Recovery ^ |
| + | | Invalid timestamp | '' | ||
| + | | Overlapping cues | '' | ||
| + | | Empty cue text | '' | ||
| + | | Unclosed cue at EOF | '' | ||
| + | | BOM detected | '' | ||
| + | | Encoding error | '' | ||
| - | Transitions indicate how one scene leads to the next. | + | ===== Known Limitations and Edge Cases ===== |
| - | Example: | + | These are areas where the format or its parser may behave unexpectedly. Test these |
| + | cases before deploying in production. | ||
| - | < | + | ==== Right-to-Left Text ==== |
| - | CUT TO: | + | |
| - | FADE OUT. | + | |
| - | </ | + | |
| - | They are usually used deliberately | + | 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 | ||
| + | better than SRT. | ||
| - | ===== Markdown-like adaptation ===== | + | ==== Overlapping Cues ==== |
| - | Some people want screenplay structure that feels closer to Markdown. | + | The spec recovers overlapping cues by using the earliest end time, but many players |
| - | That can be done with custom conventions, but it is usually not a universal standard. | + | 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 | ||
| - | Possible custom mapping: | + | ==== The 42-Character Line Limit ==== |
| - | * Heading level 1 = scene heading. | + | This is a guideline from broadcast subtitle conventions, |
| - | * Heading level 2 = character name. | + | Many desktop players ignore it entirely. However, streaming platforms (Netflix, YouTube |
| - | * Regular paragraph = dialogue. | + | auto-import) may reject |
| - | * Blockquote | + | if you're targeting platform upload. |
| - | * Emphasis = notes or special cues. | + | |
| - | Example concept: | + | ==== Multi-Line Cue Behaviour ==== |
| - | < | + | The spec allows 1–3 text lines per cue, but SRT players typically display a maximum |
| - | ====== INT. KITCHEN | + | 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. | ||
| - | A quiet kitchen. Sunlight comes through the window. | + | ==== Millisecond Precision ==== |
| - | == JORDAN == | + | 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. | ||
| - | I thought you were leaving at noon. | + | ==== Encoding and Character Set Notes ==== |
| - | < | + | * Always save as **UTF-8 without BOM** |
| - | (quietly) | + | * UTF-8 with BOM will break most SRT parsers |
| - | </ | + | * 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 | ||
| - | I was. Then I changed my mind. | + | ===== Implementation Notes ===== |
| - | </ | + | |
| - | This is not a formal screenplay standard, but it can be useful for personal notes or drafting. | + | **Language**: |
| + | **Dependencies**: | ||
| + | **Runtime**: | ||
| + | **File size limit**: 10MB source → ~1M cues \\ | ||
| + | **Output validation**: | ||
| - | ===== Workflow options | + | ===== Related Tools and Ecosystem |
| - | You can use several different workflows: | + | These are the standard tools you are likely to use alongside this format. |
| - | * Plain text only, with manual formatting later. | + | ==== Subtitle Editors ==== |
| - | * Fountain syntax plus an export tool. | + | |
| - | * Markdown-inspired notes with your own conversion rules. | + | |
| - | * A custom parser that turns your text into screenplay format. | + | |
| - | * A wiki page used as a planning reference before moving to final script software. | + | |
| - | ===== Practical pros and cons ===== | + | * [[https:// |
| + | * [[https:// | ||
| - | ^ Approach ^ Strengths ^ Weaknesses ^ | + | ==== Conversion |
| - | | Fountain plain text | Simple, portable, well-known | Needs compatible export or parser | | + | |
| - | | Markdown-like custom format | Flexible, easy to adapt | Not standardized | | + | |
| - | | Dedicated screenplay app | Good previews | + | |
| - | | Custom wiki workflow | Great for reference and drafting | Requires you to define the rules | | + | |
| - | ===== Example reference page structure ===== | + | * [[https:// |
| + | * [[https:// | ||
| - | You can organize your own notes like this: | + | ==== Validation ==== |
| - | * Syntax summary. | + | * [[https:// |
| - | * Writing rules. | + | * VLC Media Player — Reliable real-world test for SRT and WebVTT rendering. Drag subtitle file onto playing video. |
| - | * Example scene. | + | * Firefox DevTools — Open a local HTML5 video with a ''< |
| - | * Special cases. | + | |
| - | * Conversion notes. | + | |
| - | * Export instructions. | + | |
| - | * Personal conventions. | + | |
| - | ===== Personal conventions ===== | + | ==== Reference Specifications |
| - | If you build your own system, it helps to define rules such as: | + | * [[https:// |
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| - | * How to mark scene headings. | + | ==== Related Pages (this wiki) ==== |
| - | * How to mark dialogue. | + | |
| - | * How to handle emphasis. | + | |
| - | * How to note camera directions. | + | |
| - | * How to represent transitions. | + | |
| - | * Whether to include metadata in the page. | + | |
| - | Keep the rules short and consistent so the format | + | * [[fountain_syntax|Fountain: |
| - | ===== Quick cheat sheet ===== | + | ===== Quick Implementation Template |
| - | * Fountain = plain text screenplay syntax. | + | <code python> |
| - | * Any text editor can be used. | + | # |
| - | * Dedicated screenplay apps are optional. | + | # mdsub2srt.py — minimal MDSub to SRT converter |
| - | * Markdown-like screenplay formatting is possible, but usually custom. | + | import re |
| - | * A parser or export step is what turns the text into final screenplay layout. | + | import sys |
| - | ===== Example mini scene ===== | + | TIMESTAMP_RE |
| + | r' | ||
| + | ) | ||
| - | < | + | def parse_mdsub(filename): |
| - | INT. APARTMENT - MORNING | + | # Implementation here following spec above |
| + | pass | ||
| - | The coffee machine sputters and stops. | + | def print_srt(cues): |
| + | # Implementation here | ||
| + | pass | ||
| - | ELENA | + | if __name__ == " |
| - | That is not a good sound. | + | if len(sys.argv) < 2: |
| + | print(" | ||
| + | sys.exit(1) | ||
| + | cues = parse_mdsub(sys.argv[1]) | ||
| + | print_srt(cues) | ||
| + | </ | ||
| - | She taps the side of the machine. | + | ===== Sample Implementation Links ===== |
| - | ELENA | + | * Python converter: '' |
| - | Please work. | + | * Node.js version: '' |
| + | * Test files: '' | ||
| - | CUT TO: | + | ===== Final Notes ===== |
| - | EXT. BUILDING ENTRANCE - MORNING | + | This spec is complete and deterministic. Any implementation following these rules will |
| - | + | produce identical output from the same source file. | |
| - | Elena steps outside, carrying | + | |
| - | </ | + | |
| - | ===== Notes ===== | + | 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/ | ||
| - | This page is meant as a reference for writing and organizing screenplay ideas in plain text. | + | Test thoroughly |
| - | It can be expanded later with your own syntax rules, export steps, and formatting preferences. | + | before production use. |
subtitles_in_markdown.1777142940.txt.gz · Last modified: by smickster
