-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
close #6
- Loading branch information
Showing
6 changed files
with
253 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,52 @@ | ||
local config = {} | ||
|
||
-- ref: https://html.spec.whatwg.org/#elements-2 | ||
|
||
config.void_elements = { | ||
'area', | ||
'base', 'br', | ||
'col', | ||
'embed', | ||
'hr', | ||
'img', | ||
'input', | ||
'link', | ||
'meta', | ||
'param', | ||
'source', | ||
'track', | ||
'wbr', | ||
local DEFAULT_CONFIG = { | ||
html = { | ||
void_elements = { | ||
'area', | ||
'base', 'br', | ||
'col', | ||
'embed', | ||
'hr', | ||
'img', | ||
'input', | ||
'link', | ||
'meta', | ||
'param', | ||
'source', | ||
'track', | ||
'wbr', | ||
}, | ||
raw_text_elements = { | ||
'script', 'style', | ||
}, | ||
}, | ||
} | ||
|
||
config.raw_text_elements = { | ||
'script', 'style', | ||
} | ||
local utils = require('.utils') | ||
|
||
local module = {} | ||
|
||
---ACandy configuration. | ||
---@class Config | ||
---@field void_elements {[string]: boolean} | ||
---@field raw_text_elements {[string]: boolean} | ||
|
||
---@param output_type 'html' | ||
---@param modify_config fun(config: Config)? | ||
---@nodiscard | ||
function module.parse_config(output_type, modify_config) | ||
local base_config = DEFAULT_CONFIG[output_type] | ||
assert(base_config, 'unsupported output type: '..output_type) | ||
|
||
local config = { | ||
void_elements = utils.list_to_bool_dict(base_config.void_elements), | ||
raw_text_elements = utils.list_to_bool_dict(base_config.raw_text_elements), | ||
} | ||
if modify_config then | ||
modify_config(config) | ||
end | ||
return config.void_elements, config.raw_text_elements | ||
end | ||
|
||
return config | ||
return module |
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.