story-format-parser 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/open-storyfiles.py +7 -5
- package/package.json +15 -3
- package/parseStory.js +7 -5
- package/.github/dependabot.yml +0 -23
- package/.vscode/launch.json +0 -14
- package/.vscode/settings.json +0 -5
package/open-storyfiles.py
CHANGED
|
@@ -57,9 +57,10 @@ def parse_story(text: str) -> dict:
|
|
|
57
57
|
|
|
58
58
|
if key in ["day", "title", "scene", "mood"]:
|
|
59
59
|
if key == "day":
|
|
60
|
-
|
|
60
|
+
# Strict integer check so "2b" stays a string (matches the JS port)
|
|
61
|
+
if re.fullmatch(r'[+-]?[0-9]+', value):
|
|
61
62
|
day_obj["day"] = int(value)
|
|
62
|
-
|
|
63
|
+
else:
|
|
63
64
|
day_obj["day"] = value
|
|
64
65
|
else:
|
|
65
66
|
day_obj[key] = value
|
|
@@ -98,7 +99,8 @@ def parse_story(text: str) -> dict:
|
|
|
98
99
|
"text": entry_text
|
|
99
100
|
})
|
|
100
101
|
|
|
101
|
-
|
|
102
|
+
has_header = any(day_obj[k] is not None for k in ("day", "title", "scene", "mood"))
|
|
103
|
+
if has_header or len(day_obj["entries"]) > 0 or len(day_obj["extra"]) > 0:
|
|
102
104
|
days.append(day_obj)
|
|
103
105
|
|
|
104
106
|
return {"days": days, "warnings": warnings}
|
|
@@ -149,7 +151,7 @@ def serialize_story(days: list) -> str:
|
|
|
149
151
|
else:
|
|
150
152
|
body_lines.append(f"{entry.get('speaker', '')}: {entry.get('text', '')}")
|
|
151
153
|
|
|
152
|
-
full_block = "\n".join(header_lines
|
|
154
|
+
full_block = "\n".join(header_lines + ["---"] + body_lines)
|
|
153
155
|
day_blocks.append(full_block)
|
|
154
156
|
|
|
155
157
|
return "\n===\n".join(day_blocks)
|
|
@@ -176,4 +178,4 @@ python_bot: Hello from Python land!
|
|
|
176
178
|
* The script executes flawlessly.
|
|
177
179
|
"""
|
|
178
180
|
result = parse_story(sample_data)
|
|
179
|
-
print(json.dumps(result["days"], indent=2))
|
|
181
|
+
print(json.dumps(result["days"], indent=2))
|
package/package.json
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "story-format-parser",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Parser and serializer for the .STORY plain text file format.",
|
|
5
5
|
"main": "parseStory.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"parseStory.js",
|
|
8
|
+
"open-storyfiles.py",
|
|
9
|
+
"sample.story",
|
|
10
|
+
"about.md",
|
|
11
|
+
"creators-note.md",
|
|
12
|
+
"story-logo.png"
|
|
13
|
+
],
|
|
6
14
|
"scripts": {
|
|
7
|
-
"test": "node
|
|
15
|
+
"test": "node test.js"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/keane3029-lab/.story-format.git"
|
|
8
20
|
},
|
|
9
21
|
"keywords": [
|
|
10
22
|
"story",
|
|
@@ -14,4 +26,4 @@
|
|
|
14
26
|
],
|
|
15
27
|
"author": "",
|
|
16
28
|
"license": "MIT"
|
|
17
|
-
}
|
|
29
|
+
}
|
package/parseStory.js
CHANGED
|
@@ -57,8 +57,8 @@ function parseStory(text) {
|
|
|
57
57
|
|
|
58
58
|
if (["day", "title", "scene", "mood"].includes(key)) {
|
|
59
59
|
if (key === "day") {
|
|
60
|
-
|
|
61
|
-
dayObj.day =
|
|
60
|
+
// Strict integer check so "2b" stays a string (matches the Python port)
|
|
61
|
+
dayObj.day = /^[+-]?\d+$/.test(value) ? parseInt(value, 10) : value;
|
|
62
62
|
} else {
|
|
63
63
|
dayObj[key] = value;
|
|
64
64
|
}
|
|
@@ -104,7 +104,9 @@ function parseStory(text) {
|
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
const hasHeader = dayObj.day !== null || dayObj.title !== null ||
|
|
108
|
+
dayObj.scene !== null || dayObj.mood !== null;
|
|
109
|
+
if (hasHeader || dayObj.entries.length > 0 || Object.keys(dayObj.extra).length > 0) {
|
|
108
110
|
days.push(dayObj);
|
|
109
111
|
}
|
|
110
112
|
});
|
|
@@ -140,6 +142,6 @@ function serializeStory(days) {
|
|
|
140
142
|
}).join("\n===\n");
|
|
141
143
|
}
|
|
142
144
|
|
|
143
|
-
if
|
|
145
|
+
if (typeof module === "object" && module.exports) {
|
|
144
146
|
module.exports = { parseStory, serializeStory };
|
|
145
|
-
}
|
|
147
|
+
}
|
package/.github/dependabot.yml
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# .github/dependabot.yml
|
|
2
|
-
version: 2
|
|
3
|
-
updates:
|
|
4
|
-
# Check for GitHub Actions workflow updates daily
|
|
5
|
-
- package-ecosystem: "github-actions"
|
|
6
|
-
directory: "/"
|
|
7
|
-
schedule:
|
|
8
|
-
interval: "daily"
|
|
9
|
-
open-pull-requests-limit: 10
|
|
10
|
-
|
|
11
|
-
# Check for Node.js / npm package updates daily
|
|
12
|
-
- package-ecosystem: "npm"
|
|
13
|
-
directory: "/"
|
|
14
|
-
schedule:
|
|
15
|
-
interval: "daily"
|
|
16
|
-
open-pull-requests-limit: 10
|
|
17
|
-
|
|
18
|
-
# Check for Python / pip package updates daily
|
|
19
|
-
- package-ecosystem: "pip"
|
|
20
|
-
directory: "/"
|
|
21
|
-
schedule:
|
|
22
|
-
interval: "daily"
|
|
23
|
-
open-pull-requests-limit: 10
|
package/.vscode/launch.json
DELETED