markdown-up 1.5.3__tar.gz → 1.5.5__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: markdown-up
3
- Version: 1.5.3
3
+ Version: 1.5.5
4
4
  Summary: The MarkdownUp launcher
5
5
  Home-page: https://github.com/craigahobbs/markdown-up-py
6
6
  Author: Craig A. Hobbs
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = markdown-up
3
- version = 1.5.3
3
+ version = 1.5.5
4
4
  url = https://github.com/craigahobbs/markdown-up-py
5
5
  author = Craig A. Hobbs
6
6
  author_email = craigahobbs@gmail.com
@@ -0,0 +1,240 @@
1
+ # Licensed under the MIT License
2
+ # https://github.com/craigahobbs/markdown-up-py/blob/main/LICENSE
3
+
4
+ """
5
+ The MarkdownUp launcher back-end application
6
+ """
7
+
8
+ from http import HTTPStatus
9
+ import os
10
+ from pathlib import PurePosixPath
11
+
12
+ import chisel
13
+
14
+
15
+ # The map of static file extension to content-type
16
+ STATIC_EXT_TO_CONTENT_TYPE = {
17
+ '.bare': 'text/plain; charset=utf-8',
18
+ '.css': 'text/css',
19
+ '.csv': 'text/csv',
20
+ '.gif': 'image/gif',
21
+ '.htm': 'text/html; charset=utf-8',
22
+ '.html': 'text/html; charset=utf-8',
23
+ '.jpeg': 'image/jpeg',
24
+ '.jpg': 'image/jpeg',
25
+ '.js': 'application/javascript',
26
+ '.json': 'application/json',
27
+ '.markdown': 'text/markdown; charset=utf-8',
28
+ '.md': 'text/markdown; charset=utf-8',
29
+ '.mds': 'text/plain; charset=utf-8',
30
+ '.png': 'image/png',
31
+ '.smd': 'text/plain; charset=utf-8',
32
+ '.svg': 'image/svg+xml',
33
+ '.tif': 'image/tiff',
34
+ '.tiff': 'image/tiff',
35
+ '.webp': 'image/webp'
36
+ }
37
+ MARKDOWN_EXTS = ('.md', '.markdown')
38
+ HTML_EXTS = ('.html', '.htm')
39
+ INDEX_FILES = ('index.html', 'index.htm')
40
+
41
+
42
+ class MarkdownUpApplication(chisel.Application):
43
+ """
44
+ The markdown-up back-end API WSGI application class
45
+ """
46
+
47
+ __slots__ = ('root',)
48
+
49
+ def __init__(self, root):
50
+ super().__init__()
51
+ self.root = root
52
+
53
+ # Add the chisel documentation application
54
+ self.add_requests(chisel.create_doc_requests())
55
+
56
+ # Add the markdown-up application
57
+ self.add_request(MARKDOWN_UP_HTML)
58
+ self.add_request(markdown_up_index)
59
+
60
+ def __call__(self, environ, start_response):
61
+ request_method = environ.get('REQUEST_METHOD')
62
+ path_info = environ['PATH_INFO']
63
+
64
+ # Chisel API request? Otherwise, its a static request...
65
+ if request_method == 'GET' and path_info in ('/', '/markdown_up_index'):
66
+ return super().__call__(environ, start_response)
67
+
68
+ # Compute the static file path
69
+ posix_path_info = PurePosixPath(path_info)
70
+ path = os.path.join(self.root, *posix_path_info.parts[1:])
71
+
72
+ # Directory index file?
73
+ if os.path.isdir(path):
74
+ for index_file in INDEX_FILES:
75
+ index_posix_path = posix_path_info.joinpath(index_file)
76
+ index_path = os.path.join(self.root, *index_posix_path.parts[1:])
77
+ if os.path.isfile(index_path):
78
+ posix_path_info = index_posix_path
79
+ path = index_path
80
+ break
81
+
82
+ # Read the static file
83
+ try:
84
+ # Unknown method or content type?
85
+ content_type = STATIC_EXT_TO_CONTENT_TYPE.get(posix_path_info.suffix)
86
+ if request_method != 'GET' or content_type is None:
87
+ raise FileNotFoundError(path)
88
+
89
+ # Read the static file
90
+ with open(path, 'rb') as path_file:
91
+ status = HTTPStatus.OK
92
+ content = path_file.read()
93
+ except FileNotFoundError:
94
+ status = HTTPStatus.NOT_FOUND
95
+ content = status.phrase.encode(encoding='utf-8')
96
+ content_type = 'text/plain; charset=utf-8'
97
+ except: # pylint: disable=bare-except
98
+ status = HTTPStatus.INTERNAL_SERVER_ERROR
99
+ content = status.phrase.encode(encoding='utf-8')
100
+ content_type = 'text/plain; charset=utf-8'
101
+
102
+ # Static response
103
+ start_response(f'{status.value} {status.phrase}', [('Content-Type', content_type)])
104
+ return [content]
105
+
106
+
107
+ MARKDOWN_UP_HTML = chisel.StaticRequest(
108
+ 'markdown_up_html',
109
+ b'''\
110
+ <!DOCTYPE html>
111
+ <html lang="en">
112
+ <head>
113
+ <title>MarkdownUp</title>
114
+ <meta charset="UTF-8">
115
+ <meta name="description" content="MarkdownUp is a Markdown viewer">
116
+ <meta name="viewport" content="width=device-width, initial-scale=1">
117
+ <link rel="stylesheet" href="https://craigahobbs.github.io/markdown-up/app.css">
118
+
119
+ <!-- Preloads -->
120
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/data.js" as="script">
121
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/library.js" as="script">
122
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/model.js" as="script">
123
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/parser.js" as="script">
124
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/runtime.js" as="script">
125
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/runtimeAsync.js" as="script">
126
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/element-model/lib/elementModel.js" as="script">
127
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/app.js" as="script">
128
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/dataTable.js" as="script">
129
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/dataUtil.js" as="script">
130
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/lineChart.js" as="script">
131
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/script.js" as="script">
132
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/scriptLibrary.js" as="script">
133
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/markdown-model/lib/elements.js" as="script">
134
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/markdown-model/lib/parser.js" as="script">
135
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown-doc/lib/schemaMarkdownDoc.js" as="script">
136
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown/lib/encode.js" as="script">
137
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown/lib/parser.js" as="script">
138
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown/lib/schema.js" as="script">
139
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown/lib/schemaUtil.js" as="script">
140
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown/lib/typeModel.js" as="script">
141
+ <link rel="preload" href="https://craigahobbs.github.io/markdown-up/app.css" as="style">
142
+ <link rel="preload" href="https://craigahobbs.github.io/markdown-up/include/args.mds" as="fetch">
143
+ <link rel="preload" href="https://craigahobbs.github.io/markdown-up/include/forms.mds" as="fetch">
144
+ <link rel="preload" href="https://craigahobbs.github.io/markdown-up/markdown-model/static/markdown-model.css" as="style">
145
+ <link rel="preload" href="https://craigahobbs.github.io/markdown-up/launcher/app.mds" as="fetch">
146
+ </head>
147
+ <body>
148
+ </body>
149
+ <script type="module">
150
+ import {MarkdownUp} from 'https://craigahobbs.github.io/markdown-up/lib/app.js';
151
+ const app = new MarkdownUp(window, {
152
+ 'markdownText': `\\
153
+ ~~~ markdown-script
154
+ include 'https://craigahobbs.github.io/markdown-up/launcher/app.mds'
155
+ markdownUpIndex()
156
+ ~~~
157
+ `
158
+ });
159
+ app.run();
160
+ </script>
161
+ </html>
162
+ ''',
163
+ content_type='text/html; charset=utf-8',
164
+ urls=(('GET', '/'),),
165
+ doc='The MarkdownUp launcher index application',
166
+ doc_group='MarkdownUp'
167
+ )
168
+
169
+
170
+ @chisel.action(spec='''\
171
+ group "MarkdownUp"
172
+
173
+ # The MarkdownUp launcher index API
174
+ action markdown_up_index
175
+ urls
176
+ GET
177
+
178
+ query
179
+ # The relative sub-directory path
180
+ optional string(len > 0) path
181
+
182
+ output
183
+ # The index path
184
+ string path
185
+
186
+ # The parent path
187
+ optional string parent
188
+
189
+ # The path's Markdown files
190
+ optional string[len > 0] files
191
+
192
+ # The path's HTML files
193
+ optional string[len > 0] htmlFiles
194
+
195
+ # The path's sub-directories
196
+ optional string[len > 0] directories
197
+
198
+ errors
199
+ # The path is invalid
200
+ InvalidPath
201
+ ''')
202
+ def markdown_up_index(ctx, req):
203
+
204
+ # Validate the path
205
+ posix_path = PurePosixPath(req['path'] if 'path' in req else '')
206
+ if posix_path.is_absolute() or any(part == '..' for part in posix_path.parts):
207
+ raise chisel.ActionError('InvalidPath')
208
+
209
+ # Verify that the path exists
210
+ path = os.path.join(ctx.app.root, *posix_path.parts)
211
+ if not os.path.isdir(path):
212
+ raise chisel.ActionError('InvalidPath')
213
+
214
+ # Compute parent path
215
+ parent_path = str(posix_path.parent) if 'path' in req else None
216
+
217
+ # Get the list of markdown files and sub-directories from the current sub-directory
218
+ files = []
219
+ html_files = []
220
+ directories = []
221
+ for entry in os.scandir(path):
222
+ if entry.is_dir() and not entry.name.startswith('.'):
223
+ directories.append(entry.name)
224
+ elif entry.is_file(): # pragma: no branch
225
+ if entry.name.endswith(MARKDOWN_EXTS):
226
+ files.append(entry.name)
227
+ if entry.name.endswith(HTML_EXTS):
228
+ html_files.append(entry.name)
229
+
230
+ # Return the response
231
+ response = {'path': path}
232
+ if parent_path is not None and parent_path != '.':
233
+ response['parent'] = parent_path
234
+ if files:
235
+ response['files'] = sorted(files)
236
+ if html_files:
237
+ response['htmlFiles'] = sorted(html_files)
238
+ if directories:
239
+ response['directories'] = sorted(directories)
240
+ return response
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: markdown-up
3
- Version: 1.5.3
3
+ Version: 1.5.5
4
4
  Summary: The MarkdownUp launcher
5
5
  Home-page: https://github.com/craigahobbs/markdown-up-py
6
6
  Author: Craig A. Hobbs
@@ -1,192 +0,0 @@
1
- # Licensed under the MIT License
2
- # https://github.com/craigahobbs/markdown-up-py/blob/main/LICENSE
3
-
4
- """
5
- The MarkdownUp launcher back-end application
6
- """
7
-
8
- from http import HTTPStatus
9
- import os
10
- from pathlib import PurePosixPath
11
-
12
- import chisel
13
-
14
-
15
- # The map of static file extension to content-type
16
- STATIC_EXT_TO_CONTENT_TYPE = {
17
- '.bare': 'text/plain; charset=utf-8',
18
- '.css': 'text/css',
19
- '.csv': 'text/csv',
20
- '.gif': 'image/gif',
21
- '.html': 'text/html; charset=utf-8',
22
- '.jpeg': 'image/jpeg',
23
- '.jpg': 'image/jpeg',
24
- '.js': 'application/javascript',
25
- '.json': 'application/json',
26
- '.markdown': 'text/markdown; charset=utf-8',
27
- '.md': 'text/markdown; charset=utf-8',
28
- '.mds': 'text/plain; charset=utf-8',
29
- '.png': 'image/png',
30
- '.smd': 'text/plain; charset=utf-8',
31
- '.svg': 'image/svg+xml',
32
- '.tif': 'image/tiff',
33
- '.tiff': 'image/tiff',
34
- '.webp': 'image/webp'
35
- }
36
- MARKDOWN_EXTS = ('.md', '.markdown')
37
- HTML_EXTS = ('.htm', '.html')
38
-
39
-
40
- class MarkdownUpApplication(chisel.Application):
41
- """
42
- The markdown-up back-end API WSGI application class
43
- """
44
-
45
- __slots__ = ('root',)
46
-
47
- def __init__(self, root):
48
- super().__init__()
49
- self.root = root
50
-
51
- # Add the chisel documentation application
52
- self.add_requests(chisel.create_doc_requests())
53
-
54
- # Add the markdown-up application
55
- self.add_request(MARKDOWN_UP_HTML)
56
- self.add_request(markdown_up_index)
57
-
58
- def __call__(self, environ, start_response):
59
-
60
- # Handle markdown static requests
61
- path_info = PurePosixPath(environ['PATH_INFO'])
62
- content_type = STATIC_EXT_TO_CONTENT_TYPE.get(path_info.suffix)
63
- if content_type is not None:
64
- try:
65
- # Read the static file
66
- path = os.path.join(self.root, *path_info.parts[1:])
67
- with open(path, 'rb') as path_file:
68
- status = HTTPStatus.OK
69
- content = path_file.read()
70
- except FileNotFoundError:
71
- status = HTTPStatus.NOT_FOUND
72
- content = status.phrase.encode(encoding='utf-8')
73
- content_type = 'text/plain; charset=utf-8'
74
- except: # pylint: disable=bare-except
75
- status = HTTPStatus.INTERNAL_SERVER_ERROR
76
- content = status.phrase.encode(encoding='utf-8')
77
- content_type = 'text/plain; charset=utf-8'
78
-
79
- # Static response
80
- start_response(f'{status.value} {status.phrase}', [('Content-Type', content_type)])
81
- return [content]
82
-
83
- # Run the chisel application...
84
- return super().__call__(environ, start_response)
85
-
86
-
87
- MARKDOWN_UP_HTML = chisel.StaticRequest(
88
- 'markdown_up_html',
89
- b'''\
90
- <!DOCTYPE html>
91
- <html lang="en">
92
- <head>
93
- <title>MarkdownUp</title>
94
- <meta charset="UTF-8">
95
- <meta name="description" content="MarkdownUp is a Markdown viewer">
96
- <meta name="viewport" content="width=device-width, initial-scale=1">
97
- <link rel="stylesheet" href="https://craigahobbs.github.io/markdown-up/app.css">
98
- </head>
99
- <body>
100
- </body>
101
- <script type="module">
102
- import {MarkdownUp} from 'https://craigahobbs.github.io/markdown-up/lib/app.js';
103
- const app = new MarkdownUp(window, {
104
- 'markdownText': `\\
105
- ~~~ markdown-script
106
- include 'https://craigahobbs.github.io/markdown-up/launcher/app.mds'
107
- markdownUpIndex()
108
- ~~~
109
- `
110
- });
111
- app.run();
112
- </script>
113
- </html>
114
- ''',
115
- content_type='text/html; charset=utf-8',
116
- urls=(('GET', '/'),),
117
- doc='The MarkdownUp launcher index application',
118
- doc_group='MarkdownUp'
119
- )
120
-
121
-
122
- @chisel.action(spec='''\
123
- group "MarkdownUp"
124
-
125
- # The MarkdownUp launcher index API
126
- action markdown_up_index
127
- urls
128
- GET
129
-
130
- query
131
- # The relative sub-directory path
132
- optional string(len > 0) path
133
-
134
- output
135
- # The index path
136
- string path
137
-
138
- # The parent path
139
- optional string parent
140
-
141
- # The path's Markdown files
142
- optional string[len > 0] files
143
-
144
- # The path's HTML files
145
- optional string[len > 0] htmlFiles
146
-
147
- # The path's sub-directories
148
- optional string[len > 0] directories
149
-
150
- errors
151
- # The path is invalid
152
- InvalidPath
153
- ''')
154
- def markdown_up_index(ctx, req):
155
-
156
- # Validate the path
157
- posix_path = PurePosixPath(req['path'] if 'path' in req else '')
158
- if posix_path.is_absolute() or any(part == '..' for part in posix_path.parts):
159
- raise chisel.ActionError('InvalidPath')
160
-
161
- # Verify that the path exists
162
- path = os.path.join(ctx.app.root, *posix_path.parts)
163
- if not os.path.isdir(path):
164
- raise chisel.ActionError('InvalidPath')
165
-
166
- # Compute parent path
167
- parent_path = str(posix_path.parent) if 'path' in req else None
168
-
169
- # Get the list of markdown files and sub-directories from the current sub-directory
170
- files = []
171
- html_files = []
172
- directories = []
173
- for entry in os.scandir(path):
174
- if entry.is_dir() and not entry.name.startswith('.'):
175
- directories.append(entry.name)
176
- elif entry.is_file(): # pragma: no branch
177
- if entry.name.endswith(MARKDOWN_EXTS):
178
- files.append(entry.name)
179
- if entry.name.endswith(HTML_EXTS):
180
- html_files.append(entry.name)
181
-
182
- # Return the response
183
- response = {'path': path}
184
- if parent_path is not None and parent_path != '.':
185
- response['parent'] = parent_path
186
- if files:
187
- response['files'] = sorted(files)
188
- if html_files:
189
- response['htmlFiles'] = sorted(html_files)
190
- if directories:
191
- response['directories'] = sorted(directories)
192
- return response
File without changes
File without changes
File without changes