This is an old revision of the document!
Table of Contents
Markdown Processing Rules
| Source | SRT | WebVTT | ASS |
| ——– | —– | ——– | —– |
| `bold` | `bold` | `<b>bold</b>` | `{\b1}bold{\b0}` |
| `_italic_` | `_italic_` | `<i>italic</i>` | `{\i1}italic{\i0}` |
| `[SPEAKER]` | `[SPEAKER]` | `[SPEAKER]` | `{\c&Hffffff&}[SPEAKER]` |
| `«position:center»` | ignored | ignored | `{\pos(640,360)}` |
Complete Parser Pseudocode
```javascript function parseMDSub(source) {
let cues = [];
let currentCue = null;
let metadata = {};
for (let line of source.split('\n')) {
line = line.trim();
if (line.startsWith('//')) {
parseMetadata(line, metadata);
continue;
}
if (isTimestampLine(line)) {
if (currentCue) finalizeCue(currentCue, cues);
currentCue = newCue(parseTimestamp(line));
continue;
}
if (line === '') {
if (currentCue) finalizeCue(currentCue, cues);
currentCue = null;
continue;
}
if (currentCue) {
if (isSpeakerLine(line)) {
currentCue.speaker = extractSpeaker(line);
} else {
currentCue.text.push(processMarkdown(line));
}
}
}
if (currentCue) finalizeCue(currentCue, cues);
return { metadata, cues };
} ```
Validation Checklist
Before conversion, validate:
- [ ] All timestamps parse correctly - [ ] End time > start time for each cue - [ ] No overlapping timestamps - [ ] Maximum 2 lines per cue (SRT limit) - [ ] Maximum 42 characters per line (SRT recommendation) - [ ] Consistent language metadata
Error Conditions
| Error | Message | Recovery |
| ——- | ——— | ———- |
| Invalid timestamp | “Line X: malformed timestamp” | Skip line |
| Overlapping cues | “Cue X overlaps with Y” | Use earliest end time |
| Empty cue text | “Timestamp without text” | Skip cue |
| Unclosed cue | “File ends mid-cue” | Finalize last cue |
Implementation Notes
Language: JavaScript/Node.js, Python 3, or Bash Dependencies: None (pure regex + string processing) Runtime: O(n) where n = lines File size limit: 10MB source → ~1M cues Output validation: Test generated SRT/VTT in VLC, browser
Sample Implementation Links
*(Add your own scripts here)* - Python converter: `scripts/mdsub2srt.py` - Node.js version: `scripts/mdsub-parser.js` - Test files: `tests/sample.mdsub`
Quick Implementation Template
```bash #!/usr/bin/env python3 import re import sys
TIMESTAMP_RE = re.compile(r'^\[\s*(\d{2}):(\d{2}):(\d{2})\.(\d{3})\s*–>\s*(\d{2}):(\d{2}):(\d{2})\.(\d{3})\s*\]$')
def parse_mdsub(filename):
# Implementation here following spec above pass
if name == “main”:
cues = parse_mdsub(sys.argv)[1] print_srt(cues)
```
Final Notes
This spec is complete and deterministic. Any implementation following these rules will produce identical output from the same source file. Test thoroughly with edge cases before production use.
