-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand
config.extra_javascript
to support type
, async
, defer
The top-level template object `extra_javascript` gets soft-deprecated because it still reports only a list of plain strings. Themes need to take action and pick up the new config keys from `config.extra_javascript` instead.
- Loading branch information
Showing
15 changed files
with
286 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import unittest | ||
from textwrap import dedent | ||
|
||
import yaml | ||
|
||
from mkdocs.tests.base import load_config | ||
from mkdocs.utils import templates | ||
|
||
|
||
class UtilsTemplatesTests(unittest.TestCase): | ||
def test_script_tag(self): | ||
cfg_yaml = dedent( | ||
''' | ||
extra_javascript: | ||
- some_plain_javascript.js | ||
- implicitly_as_module.mjs | ||
- path: explicitly_as_module.mjs | ||
type: module | ||
- path: deferred_plain.js | ||
defer: true | ||
- path: scripts/async_module.mjs | ||
type: module | ||
async: true | ||
- path: 'aaaaaa/"my script".mjs' | ||
type: module | ||
async: true | ||
defer: true | ||
- path: plain.mjs | ||
''' | ||
) | ||
config = load_config(**yaml.safe_load(cfg_yaml)) | ||
config.extra_javascript.append('plain_string.mjs') | ||
|
||
self.assertEqual( | ||
[ | ||
str(templates.script_tag_filter({'page': None, 'base_url': 'here'}, item)) | ||
for item in config.extra_javascript | ||
], | ||
[ | ||
'<script src="here/some_plain_javascript.js"></script>', | ||
'<script src="here/implicitly_as_module.mjs" type="module"></script>', | ||
'<script src="here/explicitly_as_module.mjs" type="module"></script>', | ||
'<script src="here/deferred_plain.js" defer></script>', | ||
'<script src="here/scripts/async_module.mjs" type="module" async></script>', | ||
'<script src="here/aaaaaa/"my script".mjs" type="module" defer async></script>', | ||
'<script src="here/plain.mjs"></script>', | ||
'<script src="here/plain_string.mjs"></script>', | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.