1
1
# -*- coding: utf-8 -*-
2
2
3
3
import os
4
- import sys
5
- from datetime import date
6
- import yaml
7
4
import re
8
- from docutils import nodes
9
- from recommonmark .transform import AutoStructify
10
- from recommonmark .parser import CommonMarkParser , splitext , urlparse
5
+ from datetime import date
6
+ from pathlib import Path
11
7
from sphinx_scylladb_theme .utils import multiversion_regex_builder
12
8
from redirects_cli import cli as redirects_cli
13
9
47
43
'sphinx.ext.autosectionlabel' ,
48
44
'sphinx_scylladb_theme' ,
49
45
'sphinx_multiversion' ,
46
+ 'sphinx_scylladb_markdown'
50
47
]
51
48
52
49
# Add any paths that contain templates here, relative to this directory.
88
85
# Prefix added to all the URLs generated in the 404 page.
89
86
notfound_urls_prefix = ''
90
87
88
+ # -- Options for markdown extension
89
+ scylladb_markdown_enable = True
90
+ scylladb_markdown_recommonmark_versions = [
91
+ 'scylla-3.7.2.x' ,
92
+ 'scylla-3.10.2.x' ,
93
+ 'scylla-3.11.0.x' ,
94
+ 'scylla-3.11.2.x' ,
95
+ 'scylla-4.7.2.x' ,
96
+ 'scylla-4.10.0.x' ,
97
+ 'scylla-4.11.1.x' ,
98
+ 'scylla-4.12.0.x' ,
99
+ 'scylla-4.13.0.x' ,
100
+ 'scylla-4.14.1.x' ,
101
+ 'scylla-4.15.0.x' ,
102
+ ]
103
+ suppress_warnings = ["ref.any" , "myst.header" ,"myst.xref_missing" ]
104
+
91
105
# -- Options for multiversion extension
92
106
93
107
# Whitelist pattern for tags
151
165
152
166
# Dictionary of values to pass into the template engine’s context for all pages
153
167
html_context = {'html_baseurl' : html_baseurl }
154
-
155
- # -- Initialize Sphinx
156
-
157
- class CustomCommonMarkParser (CommonMarkParser ):
158
-
159
- def visit_document (self , node ):
160
- pass
161
-
162
- def visit_link (self , mdnode ):
163
- # Override MarkDownParser to avoid checking if relative links exists
164
- ref_node = nodes .reference ()
165
- destination = mdnode .destination
166
- _ , ext = splitext (destination )
167
-
168
- url_check = urlparse (destination )
169
- scheme_known = bool (url_check .scheme )
170
-
171
- if not scheme_known and ext .replace ('.' , '' ) in self .supported :
172
- destination = destination .replace (ext , '' )
173
- ref_node ['refuri' ] = destination
174
- ref_node .line = self ._get_line (mdnode )
175
- if mdnode .title :
176
- ref_node ['title' ] = mdnode .title
177
- next_node = ref_node
178
-
179
- self .current_node .append (next_node )
180
- self .current_node = ref_node
181
-
182
168
def replace_relative_links (app , docname , source ):
183
169
result = source [0 ]
184
170
for key in app .config .replacements :
185
171
result = re .sub (key , app .config .replacements [key ], result )
186
172
source [0 ] = result
187
173
188
-
189
- def build_finished (app , exception ):
174
+ def redirect_api_page_to_javadoc (app , exception ):
190
175
version_name = os .getenv ("SPHINX_MULTIVERSION_NAME" , "" )
191
176
version_name = "/" + version_name if version_name else ""
192
177
redirect_to = version_name + '/api/index.html'
193
- out_file = app .outdir + '/ api.html'
194
- redirects_cli .create (redirect_to = redirect_to ,out_file = out_file )
178
+ out_file = Path ( app .outdir ) / ' api.html'
179
+ redirects_cli .create (redirect_to = redirect_to , out_file = str ( out_file ) )
195
180
196
181
def setup (app ):
197
- # Setup Markdown parser
198
- app .add_source_parser (CustomCommonMarkParser )
199
- app .add_config_value ('recommonmark_config' , {
200
- 'enable_eval_rst' : True ,
201
- 'enable_auto_toc_tree' : False ,
202
- }, True )
203
- app .add_transform (AutoStructify )
204
-
205
182
# Replace DataStax links
206
183
current_slug = os .getenv ("SPHINX_MULTIVERSION_NAME" , "stable" )
207
184
replacements = {
@@ -210,7 +187,4 @@ def setup(app):
210
187
}
211
188
app .add_config_value ('replacements' , replacements , True )
212
189
app .connect ('source-read' , replace_relative_links )
213
-
214
- # Create redirect to JavaDoc API
215
- app .connect ('build-finished' , build_finished )
216
-
190
+ app .connect ('build-finished' , redirect_api_page_to_javadoc )
0 commit comments