Skip to content

Commit 321c347

Browse files
authored
Merge pull request #3 from LebToki/codex/add-stripmarkdown-helper-and-update-readme
Add markdown cleanup helper
2 parents 32790f1 + 771bfdb commit 321c347

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ FEATURES
1818
- Instant Subtitle Generation – Convert plain scripts into .srt format
1919
- CapCut Voiceover Compatibility – Auto-splits into 450-character blocks (max 500 safe)
2020
- Improved Sentence Flow – Breaks only on full stops (.) for natural voiceovers
21-
- Smart Cleanup – Strips markdown (###, ##, *, **) to prevent speech artifacts
21+
- Smart Cleanup – Sanitizes scripts with `stripMarkdown()` to remove markdown characters (###, ##, *, **) and prevent speech artifacts
2222
- Parameter Controls – Customize:
2323
• Words Per Second (WPS)
2424
• Minimum duration per block

generate_srt.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ function cleanOutput($data) {
1010
return json_encode($data, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
1111
}
1212

13+
function stripMarkdown($text) {
14+
return preg_replace('/[#*]+/', '', $text);
15+
}
16+
1317
try {
1418
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
1519
$input = file_get_contents('php://input');
@@ -55,6 +59,7 @@ function processScript($script, $wpm, $minTime, $punctuationPad, $maxLength, $na
5559
if ($minTime < 0.5 || $minTime > 10) throw new Exception('Invalid minimum duration');
5660
if ($punctuationPad < 0 || $punctuationPad > 2) throw new Exception('Invalid punctuation padding');
5761

62+
$script = stripMarkdown($script);
5863
$chunks = splitIntoChunks($script, $maxLength);
5964
if (empty($chunks)) throw new Exception('No valid chunks found in script');
6065

0 commit comments

Comments
 (0)