@shzlx/ui-default 4.58.2
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/README.md +5 -0
- package/api.ts +61 -0
- package/backendlib/builder.ts +182 -0
- package/backendlib/markdown-it-imsize.ts +235 -0
- package/backendlib/markdown-it-katex.ts +139 -0
- package/backendlib/markdown-it-media.ts +163 -0
- package/backendlib/markdown-it-xss.ts +200 -0
- package/backendlib/markdown.js +64 -0
- package/backendlib/misc.ts +54 -0
- package/backendlib/template.ts +279 -0
- package/breakpoints.json +5 -0
- package/components/DOMAttachedObject.ts +128 -0
- package/components/autocomplete/AssignSelectAutoComplete.tsx +22 -0
- package/components/autocomplete/CustomSelectAutoComplete.tsx +23 -0
- package/components/autocomplete/DomainSelectAutoComplete.tsx +18 -0
- package/components/autocomplete/FileSelectAutoComplete.tsx +26 -0
- package/components/autocomplete/LanguageSelectAutoComplete.tsx +24 -0
- package/components/autocomplete/ProblemSelectAutoComplete.tsx +18 -0
- package/components/autocomplete/UserSelectAutoComplete.tsx +23 -0
- package/components/autocomplete/components/AssignSelectAutoComplete.tsx +118 -0
- package/components/autocomplete/components/DomainSelectAutoComplete.tsx +53 -0
- package/components/autocomplete/components/FileSelectAutoComplete.tsx +50 -0
- package/components/autocomplete/components/LanguageSelectAutoComplete.tsx +48 -0
- package/components/autocomplete/components/ProblemSelectAutoComplete.tsx +54 -0
- package/components/autocomplete/components/UserSelectAutoComplete.tsx +54 -0
- package/components/autocomplete/domainselectautocomplete.page.styl +6 -0
- package/components/autocomplete/index.tsx +110 -0
- package/components/autocomplete/problemselectautocomplete.page.styl +6 -0
- package/components/autocomplete/userselectautocomplete.page.styl +6 -0
- package/components/browser-update.page.ts +27 -0
- package/components/calendar/calendar.page.styl +129 -0
- package/components/calendar/index.js +367 -0
- package/components/clipboard.page.ts +23 -0
- package/components/contest/contest.page.styl +119 -0
- package/components/contest/contest.page.ts +23 -0
- package/components/contest/contest_sidebar.page.styl +21 -0
- package/components/contest/problem-contest-bg.png +0 -0
- package/components/contest/problem-contest-bg@2x.png +0 -0
- package/components/customFont.page.tsx +90 -0
- package/components/datepicker/datepicker.page.tsx +94 -0
- package/components/dialog/DomDialog.ts +145 -0
- package/components/dialog/dialog.page.styl +40 -0
- package/components/dialog/index.tsx +285 -0
- package/components/discussion/CommentBox.js +103 -0
- package/components/discussion/collapsible.page.styl +40 -0
- package/components/discussion/collapsible.page.tsx +62 -0
- package/components/discussion/comments.page.styl +142 -0
- package/components/discussion/comments.page.tsx +192 -0
- package/components/discussion/discussion.page.styl +17 -0
- package/components/discussion/history.page.tsx +81 -0
- package/components/discussion/reaction.page.styl +30 -0
- package/components/discussion/reaction.page.tsx +103 -0
- package/components/drop/drop.page.styl +40 -0
- package/components/dropdown/Dropdown.js +50 -0
- package/components/dropdown/dropdown.page.styl +33 -0
- package/components/dropdown/dropdown.page.ts +8 -0
- package/components/editor/cmeditor.page.ts +23 -0
- package/components/editor/cmeditor.styl +10 -0
- package/components/editor/index.tsx +293 -0
- package/components/editor/mdeditor.ts +60 -0
- package/components/editor/textareaHandler.ts +29 -0
- package/components/footer/footer.page.styl +94 -0
- package/components/footer/footer.page.ts +26 -0
- package/components/form/button.page.default.styl +59 -0
- package/components/form/button.page.styl +36 -0
- package/components/form/checkbox.page.styl +89 -0
- package/components/form/form.page.styl +200 -0
- package/components/form/form.page.ts +20 -0
- package/components/form/multiSelectCheckbox.page.js +46 -0
- package/components/form/radiobox.page.styl +62 -0
- package/components/form/select.page.styl +29 -0
- package/components/form/textbox.page.styl +79 -0
- package/components/form/textbox.page.ts +21 -0
- package/components/form/var.inc.styl +14 -0
- package/components/header/header.page.styl +79 -0
- package/components/highlighter/code-example.js +111 -0
- package/components/highlighter/highlighter.page.styl +99 -0
- package/components/highlighter/highlighter.page.ts +72 -0
- package/components/highlighter/meta.js +15 -0
- package/components/highlighter/prismjs.js +122 -0
- package/components/hint.page.styl +9 -0
- package/components/hint.ts +19 -0
- package/components/hitokoto/index.page.js +21 -0
- package/components/hotkey/hotkey.page.js +83 -0
- package/components/katex/katex.page.js +26 -0
- package/components/katex/katex.page.styl +2 -0
- package/components/languageselect.tsx +94 -0
- package/components/loader/loader.page.styl +40 -0
- package/components/mantine.page.tsx +39 -0
- package/components/marker/Marker.js +192 -0
- package/components/marker/MarkerReactive.js +55 -0
- package/components/marker/marker.page.js +8 -0
- package/components/marker/marker.page.styl +57 -0
- package/components/media/media.page.js +46 -0
- package/components/menu/menu-heading.page.js +28 -0
- package/components/menu/menu.page.js +18 -0
- package/components/menu/menu.page.styl +68 -0
- package/components/message/index.page.ts +166 -0
- package/components/message/worker.ts +110 -0
- package/components/messagepad/DialogueListItem.page.styl +28 -0
- package/components/messagepad/DialogueListItemComponent.jsx +39 -0
- package/components/messagepad/Message.page.styl +64 -0
- package/components/messagepad/MessageComponent.jsx +33 -0
- package/components/messagepad/MessagePad.page.styl +99 -0
- package/components/messagepad/MessagePadDialogueContentContainer.jsx +104 -0
- package/components/messagepad/MessagePadDialogueListContainer.jsx +49 -0
- package/components/messagepad/MessagePadInputContainer.jsx +100 -0
- package/components/messagepad/index.jsx +49 -0
- package/components/messagepad/reducers/activeId.ts +36 -0
- package/components/messagepad/reducers/dialogues.js +53 -0
- package/components/messagepad/reducers/index.ts +14 -0
- package/components/messagepad/reducers/inputs.js +43 -0
- package/components/messagepad/reducers/isPosting.ts +49 -0
- package/components/monaco/index.ts +178 -0
- package/components/monaco/languages/markdown.ts +97 -0
- package/components/monaco/languages/typescript.ts +45 -0
- package/components/monaco/languages/yaml.ts +22 -0
- package/components/monaco/loader.ts +96 -0
- package/components/monaco/monaco.styl +30 -0
- package/components/monaco/nls.js +31 -0
- package/components/monaco/schema/problemconfig.ts +123 -0
- package/components/navigation/hamburgers.page.styl +87 -0
- package/components/navigation/nav-logo-small_dark.png +0 -0
- package/components/navigation/navigation.page.js +203 -0
- package/components/navigation/navigation.page.styl +211 -0
- package/components/notification/index.ts +105 -0
- package/components/notification/notification.page.js +14 -0
- package/components/notification/notification.page.styl +84 -0
- package/components/nprogress.page.styl +50 -0
- package/components/omnisearch/index.page.tsx +124 -0
- package/components/omnisearch/omnibar.page.styl +138 -0
- package/components/pager/pager.page.styl +57 -0
- package/components/preview/preview.page.ts +187 -0
- package/components/problem/create.page.js +12 -0
- package/components/problem/list.page.js +9 -0
- package/components/problem/rp.page.styl +4 -0
- package/components/problem/tag.page.styl +84 -0
- package/components/problemconfig/BasicForm.tsx +92 -0
- package/components/problemconfig/ProblemConfigEditor.tsx +170 -0
- package/components/problemconfig/ProblemConfigForm.tsx +140 -0
- package/components/problemconfig/ProblemConfigTree.tsx +163 -0
- package/components/problemconfig/ProblemType.tsx +165 -0
- package/components/problemconfig/index.tsx +91 -0
- package/components/problemconfig/reducer/config.ts +173 -0
- package/components/problemconfig/reducer/index.ts +11 -0
- package/components/problemconfig/reducer/testdata.ts +16 -0
- package/components/problemconfig/tree/AddTestcase.tsx +137 -0
- package/components/problemconfig/tree/SelectionManager.tsx +140 -0
- package/components/problemconfig/tree/SubtaskSettings.tsx +180 -0
- package/components/problemconfig/tree/Testcase.tsx +98 -0
- package/components/profile/backgrounds/1.jpg +0 -0
- package/components/profile/backgrounds/10.jpg +0 -0
- package/components/profile/backgrounds/11.jpg +0 -0
- package/components/profile/backgrounds/12.jpg +0 -0
- package/components/profile/backgrounds/13.jpg +0 -0
- package/components/profile/backgrounds/14.jpg +0 -0
- package/components/profile/backgrounds/15.jpg +0 -0
- package/components/profile/backgrounds/16.jpg +0 -0
- package/components/profile/backgrounds/17.jpg +0 -0
- package/components/profile/backgrounds/18.jpg +0 -0
- package/components/profile/backgrounds/19.jpg +0 -0
- package/components/profile/backgrounds/2.jpg +0 -0
- package/components/profile/backgrounds/20.jpg +0 -0
- package/components/profile/backgrounds/21.jpg +0 -0
- package/components/profile/backgrounds/3.jpg +0 -0
- package/components/profile/backgrounds/4.jpg +0 -0
- package/components/profile/backgrounds/5.jpg +0 -0
- package/components/profile/backgrounds/6.jpg +0 -0
- package/components/profile/backgrounds/7.jpg +0 -0
- package/components/profile/backgrounds/8.jpg +0 -0
- package/components/profile/backgrounds/9.jpg +0 -0
- package/components/profile/backgrounds/gen_thumbnails.sh +7 -0
- package/components/profile/backgrounds/thumbnail/1.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/10.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/11.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/12.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/13.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/14.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/15.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/16.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/17.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/18.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/19.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/2.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/20.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/21.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/3.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/4.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/5.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/6.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/7.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/8.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/9.jpg +0 -0
- package/components/profile/profile.page.styl +23 -0
- package/components/react/DomComponent.tsx +14 -0
- package/components/react/IconComponent.tsx +20 -0
- package/components/record/record.page.styl +26 -0
- package/components/rotator/index.js +75 -0
- package/components/rotator/rotator.page.styl +20 -0
- package/components/scratchpad/DataInput.page.styl +17 -0
- package/components/scratchpad/DataInputComponent.jsx +45 -0
- package/components/scratchpad/Editor.page.styl +13 -0
- package/components/scratchpad/Panel.page.styl +18 -0
- package/components/scratchpad/PanelButton.page.styl +15 -0
- package/components/scratchpad/PanelButtonComponent.jsx +19 -0
- package/components/scratchpad/PanelComponent.jsx +25 -0
- package/components/scratchpad/ScratchpadEditorContainer.tsx +137 -0
- package/components/scratchpad/ScratchpadPretestContainer.jsx +57 -0
- package/components/scratchpad/ScratchpadRecordsContainer.jsx +45 -0
- package/components/scratchpad/ScratchpadRecordsRowContainer.jsx +83 -0
- package/components/scratchpad/ScratchpadSettings.tsx +48 -0
- package/components/scratchpad/ScratchpadToolbarContainer.jsx +190 -0
- package/components/scratchpad/Tab.page.styl +24 -0
- package/components/scratchpad/Toolbar.page.styl +53 -0
- package/components/scratchpad/ToolbarComponent.jsx +85 -0
- package/components/scratchpad/index.tsx +132 -0
- package/components/scratchpad/reducers/editor.ts +24 -0
- package/components/scratchpad/reducers/index.ts +17 -0
- package/components/scratchpad/reducers/pretest.ts +34 -0
- package/components/scratchpad/reducers/records.ts +40 -0
- package/components/scratchpad/reducers/state.ts +10 -0
- package/components/scratchpad/reducers/ui.ts +152 -0
- package/components/scratchpad/scratchpad.page.styl +55 -0
- package/components/scratchpad/var.inc.styl +2 -0
- package/components/selectUser.tsx +16 -0
- package/components/signin/signInDialog.page.js +84 -0
- package/components/signin/signin_dialog.page.styl +57 -0
- package/components/smoothscroll/smoothscroll.page.js +44 -0
- package/components/socket/index.ts +68 -0
- package/components/star/star.page.styl +20 -0
- package/components/star/star.page.ts +58 -0
- package/components/sticky/sticky.page.js +66 -0
- package/components/tab/Tab.js +168 -0
- package/components/tab/tab.page.js +9 -0
- package/components/tab/tab.page.styl +105 -0
- package/components/tab/var.inc.styl +3 -0
- package/components/table/StyledTable.js +51 -0
- package/components/table/styledTable.page.js +8 -0
- package/components/table/table.page.styl +73 -0
- package/components/time/time.page.js +47 -0
- package/components/tooltip/Tooltip.js +49 -0
- package/components/tooltip/tooltip.page.js +29 -0
- package/components/tooltip/tooltip.page.styl +69 -0
- package/components/training/training.page.styl +25 -0
- package/components/upload.tsx +103 -0
- package/components/vote/vote.page.js +43 -0
- package/components/zipDownloader/index.ts +157 -0
- package/constant/domain.js +21 -0
- package/constant/message.js +5 -0
- package/constant/record.js +52 -0
- package/context.ts +11 -0
- package/entry.js +72 -0
- package/hydro.ts +112 -0
- package/index.ts +226 -0
- package/lazyload.ts +69 -0
- package/locales/en.yaml +71 -0
- package/locales/ko.yaml +823 -0
- package/locales/zh.yaml +1137 -0
- package/locales/zh_TW.yaml +1133 -0
- package/misc/Page.ts +49 -0
- package/misc/PageLoader.js +31 -0
- package/misc/float.styl +14 -0
- package/misc/grid.styl +1048 -0
- package/misc/immersive-background.jpg +0 -0
- package/misc/immersive-background@2x.jpg +0 -0
- package/misc/immersive.styl +23 -0
- package/misc/nothing.styl +13 -0
- package/misc/puzzled_twd2.svg +1 -0
- package/misc/section.styl +105 -0
- package/misc/slideout.styl +46 -0
- package/misc/structure.styl +158 -0
- package/misc/textalign.styl +11 -0
- package/misc/typography.styl +485 -0
- package/package.json +148 -0
- package/polyfill.ts +90 -0
- package/postcss.config.js +15 -0
- package/sentry.ts +26 -0
- package/service-worker.ts +265 -0
- package/setting.yaml +98 -0
- package/templates/about.html +14 -0
- package/templates/bsod.html +35 -0
- package/templates/components/comments_discussion.html +165 -0
- package/templates/components/comments_solution.html +171 -0
- package/templates/components/contest.html +12 -0
- package/templates/components/form.html +214 -0
- package/templates/components/home.html +20 -0
- package/templates/components/homework.html +8 -0
- package/templates/components/md_hint.html +39 -0
- package/templates/components/noscript_note.html +15 -0
- package/templates/components/nothing.html +6 -0
- package/templates/components/paginator.html +25 -0
- package/templates/components/problem.html +33 -0
- package/templates/components/record.html +21 -0
- package/templates/components/sidemenu.html +11 -0
- package/templates/components/user.html +49 -0
- package/templates/contest_balloon.html +48 -0
- package/templates/contest_clarification.html +103 -0
- package/templates/contest_detail.html +56 -0
- package/templates/contest_edit.html +259 -0
- package/templates/contest_main.html +146 -0
- package/templates/contest_manage.html +80 -0
- package/templates/contest_print.html +27 -0
- package/templates/contest_problemlist.html +231 -0
- package/templates/contest_scoreboard.html +46 -0
- package/templates/contest_scoreboard_download_html.html +71 -0
- package/templates/contest_user.html +47 -0
- package/templates/discussion_create.html +28 -0
- package/templates/discussion_detail.html +149 -0
- package/templates/discussion_edit.html +30 -0
- package/templates/discussion_main_or_node.html +47 -0
- package/templates/domain_base.html +26 -0
- package/templates/domain_create.html +55 -0
- package/templates/domain_dashboard.html +45 -0
- package/templates/domain_edit.html +6 -0
- package/templates/domain_group.html +51 -0
- package/templates/domain_join.html +47 -0
- package/templates/domain_join_applications.html +67 -0
- package/templates/domain_permission.html +66 -0
- package/templates/domain_role.html +71 -0
- package/templates/domain_user.html +86 -0
- package/templates/domain_user_raw.html +5 -0
- package/templates/error.html +25 -0
- package/templates/home_domain.html +64 -0
- package/templates/home_files.html +16 -0
- package/templates/home_messages.html +9 -0
- package/templates/home_security.html +224 -0
- package/templates/home_settings.html +21 -0
- package/templates/homework_detail.html +82 -0
- package/templates/homework_edit.html +138 -0
- package/templates/homework_files.html +24 -0
- package/templates/homework_main.html +76 -0
- package/templates/layout/basic.html +27 -0
- package/templates/layout/home_base.html +13 -0
- package/templates/layout/html5.html +74 -0
- package/templates/layout/immersive.html +22 -0
- package/templates/layout/mail.html +31 -0
- package/templates/layout/simple.html +4 -0
- package/templates/layout/wiki_base.html +16 -0
- package/templates/main.html +22 -0
- package/templates/manage_base.html +24 -0
- package/templates/manage_config.html +6 -0
- package/templates/manage_dashboard.html +27 -0
- package/templates/manage_script.html +56 -0
- package/templates/manage_setting.html +6 -0
- package/templates/manage_user_import.html +23 -0
- package/templates/manage_user_priv.html +76 -0
- package/templates/partials/category.html +19 -0
- package/templates/partials/contest.html +3 -0
- package/templates/partials/contest_balloon.html +37 -0
- package/templates/partials/contest_sidebar.html +150 -0
- package/templates/partials/contest_sidebar_management.html +56 -0
- package/templates/partials/contest_user.html +19 -0
- package/templates/partials/discussion_edit_form.html +45 -0
- package/templates/partials/discussion_list.html +50 -0
- package/templates/partials/discussion_nodes_widget.html +17 -0
- package/templates/partials/files.html +49 -0
- package/templates/partials/footer.html +108 -0
- package/templates/partials/hamburger.html +7 -0
- package/templates/partials/header_mobile.html +12 -0
- package/templates/partials/homepage/bulletin.html +7 -0
- package/templates/partials/homepage/contest.html +48 -0
- package/templates/partials/homepage/discussion.html +13 -0
- package/templates/partials/homepage/discussion_nodes.html +4 -0
- package/templates/partials/homepage/error.html +5 -0
- package/templates/partials/homepage/hitokoto.html +6 -0
- package/templates/partials/homepage/homework.html +45 -0
- package/templates/partials/homepage/problem_search.html +13 -0
- package/templates/partials/homepage/ranking.html +39 -0
- package/templates/partials/homepage/recent_problems.html +17 -0
- package/templates/partials/homepage/starred_problems.html +15 -0
- package/templates/partials/homepage/suggestion.html +34 -0
- package/templates/partials/homepage/training.html +50 -0
- package/templates/partials/homework.html +3 -0
- package/templates/partials/homework_default_penalty_rules.yaml +6 -0
- package/templates/partials/homework_sidebar.html +93 -0
- package/templates/partials/login_dialog.html +56 -0
- package/templates/partials/manage_user_priv.html +78 -0
- package/templates/partials/nav.html +138 -0
- package/templates/partials/problem-sidebar-information.html +25 -0
- package/templates/partials/problem.html +2 -0
- package/templates/partials/problem_category_dialog.html +43 -0
- package/templates/partials/problem_default.md +26 -0
- package/templates/partials/problem_description.html +33 -0
- package/templates/partials/problem_files.html +63 -0
- package/templates/partials/problem_list.html +68 -0
- package/templates/partials/problem_lucky.html +10 -0
- package/templates/partials/problem_sidebar.html +14 -0
- package/templates/partials/problem_sidebar_contest.html +43 -0
- package/templates/partials/problem_sidebar_homework.html +42 -0
- package/templates/partials/problem_sidebar_normal.html +152 -0
- package/templates/partials/problem_stat.html +3 -0
- package/templates/partials/scoreboard.html +79 -0
- package/templates/partials/setting.html +92 -0
- package/templates/partials/training_default.json +14 -0
- package/templates/partials/training_detail.html +153 -0
- package/templates/partials/user.html +2 -0
- package/templates/partials/user_detail/activity.html +18 -0
- package/templates/partials/user_detail/solution.html +29 -0
- package/templates/problem_config.html +39 -0
- package/templates/problem_detail.html +150 -0
- package/templates/problem_edit.html +111 -0
- package/templates/problem_files.html +91 -0
- package/templates/problem_hack.html +41 -0
- package/templates/problem_import.html +58 -0
- package/templates/problem_main.html +100 -0
- package/templates/problem_solution.html +55 -0
- package/templates/problem_statistics.html +96 -0
- package/templates/problem_submit.html +40 -0
- package/templates/ranking.html +81 -0
- package/templates/record_detail.html +134 -0
- package/templates/record_detail_status.html +93 -0
- package/templates/record_detail_summary.html +19 -0
- package/templates/record_main.html +142 -0
- package/templates/record_main_tr.html +35 -0
- package/templates/status.html +75 -0
- package/templates/training_detail.html +120 -0
- package/templates/training_edit.html +68 -0
- package/templates/training_files.html +64 -0
- package/templates/training_main.html +107 -0
- package/templates/user_changemail_mail.html +6 -0
- package/templates/user_changemail_mail_sent.html +9 -0
- package/templates/user_delete_pending.html +10 -0
- package/templates/user_detail.html +181 -0
- package/templates/user_login.html +46 -0
- package/templates/user_logout.html +13 -0
- package/templates/user_lostpass.html +27 -0
- package/templates/user_lostpass_mail.html +6 -0
- package/templates/user_lostpass_mail_sent.html +9 -0
- package/templates/user_lostpass_with_code.html +29 -0
- package/templates/user_register.html +22 -0
- package/templates/user_register_mail.html +6 -0
- package/templates/user_register_mail_sent.html +9 -0
- package/templates/user_register_with_code.html +35 -0
- package/templates/user_sudo.html +54 -0
- package/templates/user_sudo_redirect.html +18 -0
- package/templates/wiki_help.html +189 -0
- package/theme/bp6-compat.css +48 -0
- package/theme/dark.styl +397 -0
- package/theme/default.js +33 -0
- package/typed.d.ts +20 -0
- package/utils/base.ts +209 -0
- package/utils/base64.js +104 -0
- package/utils/db.ts +32 -0
- package/utils/index.ts +73 -0
- package/utils/loadReactRedux.ts +32 -0
- package/utils/mediaQuery.ts +13 -0
- package/utils/pjax.js +148 -0
- package/utils/slide.ts +57 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
/* eslint-disable regexp/prefer-question-quantifier */
|
|
3
|
+
/* eslint-disable regexp/no-useless-non-capturing-group */
|
|
4
|
+
/* eslint-disable regexp/optimal-quantifier-concatenation */
|
|
5
|
+
|
|
6
|
+
import _ from 'lodash';
|
|
7
|
+
import type MarkdownIt from 'markdown-it';
|
|
8
|
+
import { v4 as uuid } from 'uuid';
|
|
9
|
+
|
|
10
|
+
const allowFullScreen = ' webkitallowfullscreen mozallowfullscreen allowfullscreen';
|
|
11
|
+
|
|
12
|
+
const ytRegex = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
|
|
13
|
+
function youtubeParser(url: string) {
|
|
14
|
+
const match = url.match(ytRegex);
|
|
15
|
+
return match && match[7].length === 11 ? match[7] : url;
|
|
16
|
+
}
|
|
17
|
+
// eslint-disable-next-line regexp/no-empty-alternative
|
|
18
|
+
const vimeoRegex = /https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^/]*)\/videos\/|album\/(\d+)\/video\/|)(\d+)(?:$|\/|\?)/;
|
|
19
|
+
function vimeoParser(url: string) {
|
|
20
|
+
const match = url.match(vimeoRegex);
|
|
21
|
+
return match && typeof match[3] === 'string' ? match[3] : url;
|
|
22
|
+
}
|
|
23
|
+
const vineRegex = /^http(?:s?):\/\/(?:www\.)?vine\.co\/v\/([a-zA-Z0-9]{1,13}).*/;
|
|
24
|
+
function vineParser(url: string) {
|
|
25
|
+
const match = url.match(vineRegex);
|
|
26
|
+
return match && match[1].length === 11 ? match[1] : url;
|
|
27
|
+
}
|
|
28
|
+
const preziRegex = /^https:\/\/prezi.com\/(.[^/]+)/;
|
|
29
|
+
function preziParser(url: string) {
|
|
30
|
+
const match = url.match(preziRegex);
|
|
31
|
+
return match ? match[1] : url;
|
|
32
|
+
}
|
|
33
|
+
const EMBED_REGEX = /@\[([a-zA-Z].+?)\]\((.*?)\)/;
|
|
34
|
+
function extractVideoParameters(url: string) {
|
|
35
|
+
const parameterMap = new Map();
|
|
36
|
+
const params = url.replace(/&/gi, '&').split(/[#?&]/);
|
|
37
|
+
if (params.length > 1) {
|
|
38
|
+
for (let i = 1; i < params.length; i += 1) {
|
|
39
|
+
const keyValue = params[i].split('=');
|
|
40
|
+
if (keyValue.length > 1) parameterMap.set(keyValue[0], keyValue[1]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return parameterMap;
|
|
44
|
+
}
|
|
45
|
+
function resourceUrl(service: string, src: string, url: string) {
|
|
46
|
+
if (service === 'youtube') {
|
|
47
|
+
const parameters = extractVideoParameters(url);
|
|
48
|
+
const timeParameter = parameters.get('t');
|
|
49
|
+
if (timeParameter !== undefined) {
|
|
50
|
+
let startTime = 0;
|
|
51
|
+
const timeParts = timeParameter.match(/[0-9]+/g);
|
|
52
|
+
let j = 0;
|
|
53
|
+
while (timeParts.length > 0) {
|
|
54
|
+
startTime += Number(timeParts.pop()) * (60 ** j);
|
|
55
|
+
j += 1;
|
|
56
|
+
}
|
|
57
|
+
parameters.set('start', startTime);
|
|
58
|
+
parameters.delete('t');
|
|
59
|
+
}
|
|
60
|
+
parameters.delete('v');
|
|
61
|
+
parameters.delete('feature');
|
|
62
|
+
parameters.delete('origin');
|
|
63
|
+
const parameterArray = Array.from(parameters, (p) => p.join('='));
|
|
64
|
+
const parameterPos = src.indexOf('?');
|
|
65
|
+
let finalUrl = `https://www.youtube.com/embed/${parameterPos > -1 ? src.substring(0, parameterPos) : src}`;
|
|
66
|
+
if (parameterArray.length > 0) finalUrl += `?${parameterArray.join('&')}`;
|
|
67
|
+
return finalUrl;
|
|
68
|
+
}
|
|
69
|
+
if (service === 'bilibili') {
|
|
70
|
+
if (src.startsWith('http')) src = src.split('/').pop();
|
|
71
|
+
if (src.toLowerCase().startsWith('av')) src = src.toLowerCase().split('av')[1];
|
|
72
|
+
src = src.split('?')[0];
|
|
73
|
+
return `//player.bilibili.com/player.html?${src.startsWith('BV') ? 'bvid' : 'aid'}=${src}&autoplay=0`;
|
|
74
|
+
}
|
|
75
|
+
if (service === 'msoffice') return `https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(src)}`;
|
|
76
|
+
if (service === 'youku') return `https://player.youku.com/embed/${src}`;
|
|
77
|
+
if (service === 'vimeo') return `https://player.vimeo.com/video/${src}`;
|
|
78
|
+
if (service === 'vine') return `https://vine.co/v/${src}/embed/simple`;
|
|
79
|
+
if (service === 'prezi') {
|
|
80
|
+
return `https://prezi.com/embed/${src}/?bgcolor=ffffff&lock_to_path=0&autoplay=0&autohide_ctrls=0&`
|
|
81
|
+
+ 'landing_data=bHVZZmNaNDBIWnNjdEVENDRhZDFNZGNIUE43MHdLNWpsdFJLb2ZHanI5N1lQVHkxSHFxazZ0UUNCRHloSXZROHh3PT0&'
|
|
82
|
+
+ 'landing_sign=1kD6c0N6aYpMUS0wxnQjxzSqZlEB8qNFdxtdjYhwSuI';
|
|
83
|
+
}
|
|
84
|
+
return src;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
declare module 'hydrooj' {
|
|
88
|
+
interface ModuleInterfaces {
|
|
89
|
+
richmedia: {
|
|
90
|
+
get: (service: string, src: string, md: MarkdownIt) => string | null;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function Media(md: MarkdownIt, { pdfToolbar = false }: { pdfToolbar?: boolean } = {}) {
|
|
96
|
+
const supported = ['youtube', 'vimeo', 'vine', 'prezi', 'bilibili', 'youku', 'msoffice'];
|
|
97
|
+
md.renderer.rules.video = function tokenizeReturn(tokens, idx) {
|
|
98
|
+
let src = md.utils.escapeHtml(tokens[idx].attrGet('src'));
|
|
99
|
+
const service = md.utils.escapeHtml(tokens[idx].attrGet('service')).toLowerCase();
|
|
100
|
+
if (Hydro?.module?.richmedia?.[service]) {
|
|
101
|
+
const result = Hydro?.module?.richmedia[service].get(service, src, md);
|
|
102
|
+
if (result) return result;
|
|
103
|
+
}
|
|
104
|
+
if (service === 'pdf') {
|
|
105
|
+
if (['file://', './', '../'].some((i) => src.startsWith(i)) || (src[1] === '/' && src[2] !== '/')) src += src.includes('?') ? '&noDisposition=1' : '?noDisposition=1';
|
|
106
|
+
// A response with has content-disposition header causes the browser to download the file automatically.
|
|
107
|
+
// As we cannot control response header from external sites, we block embedding external PDFs.
|
|
108
|
+
else return `<p>Embedding an external PDF is no longer supported.</p> <a href="${_.escape(src)}">Download</a>`;
|
|
109
|
+
return `\
|
|
110
|
+
<object classid="clsid:${uuid().toUpperCase()}">
|
|
111
|
+
<param name="SRC" value="${src}">
|
|
112
|
+
<embed type="application/pdf" width="100%" style="min-height:100vh;border:none;" fullscreen="yes" src="${src}#toolbar=${pdfToolbar ? '0' : '1'}&navpanes=0&view=FitH">
|
|
113
|
+
<noembed></noembed>
|
|
114
|
+
</embed>
|
|
115
|
+
</object>`;
|
|
116
|
+
}
|
|
117
|
+
if (['url', 'video'].includes(service)) {
|
|
118
|
+
return `\
|
|
119
|
+
<video width="100%" controls>
|
|
120
|
+
<source src="${src}" type="${src.endsWith('ogg') ? 'video/ogg' : 'video/mp4'}">
|
|
121
|
+
Your browser doesn't support video tag.
|
|
122
|
+
</video>`;
|
|
123
|
+
}
|
|
124
|
+
if (supported.includes(service)) {
|
|
125
|
+
return `\
|
|
126
|
+
<iframe class="embed-responsive-item ${service}-player" type="text/html" \
|
|
127
|
+
width="100%" style="min-height: 500px" ${allowFullScreen} \
|
|
128
|
+
src="${resourceUrl(service, src, tokens[idx].attrGet('url'))}"
|
|
129
|
+
scrolling="no" border="0" frameborder="no" framespacing="0"></iframe>`;
|
|
130
|
+
}
|
|
131
|
+
return `<div data-${service}>${md.utils.escapeHtml(src)}</div>`;
|
|
132
|
+
};
|
|
133
|
+
md.inline.ruler.before('emphasis', 'video', (state, silent) => {
|
|
134
|
+
const theState = state;
|
|
135
|
+
const oldPos = state.pos;
|
|
136
|
+
if (state.src.charCodeAt(oldPos) !== 0x40
|
|
137
|
+
||/* @ */ state.src.charCodeAt(oldPos + 1) !== 0x5B/* [ */) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
const match = EMBED_REGEX.exec(state.src.slice(state.pos, state.src.length));
|
|
141
|
+
if (!match || match.length < 3) return false;
|
|
142
|
+
let [, service, src] = match;
|
|
143
|
+
service = service.toLowerCase();
|
|
144
|
+
if (service === 'youtube') src = youtubeParser(src);
|
|
145
|
+
else if (service === 'vimeo') src = vimeoParser(src);
|
|
146
|
+
else if (service === 'vine') src = vineParser(src);
|
|
147
|
+
else if (service === 'prezi') src = preziParser(src);
|
|
148
|
+
if (src === ')') src = '';
|
|
149
|
+
const serviceStart = oldPos + 2;
|
|
150
|
+
if (!silent) {
|
|
151
|
+
theState.pos = serviceStart;
|
|
152
|
+
const newState = new theState.md.inline.State(service, theState.md, theState.env, []);
|
|
153
|
+
newState.md.inline.tokenize(newState);
|
|
154
|
+
const token = theState.push('video', '', undefined);
|
|
155
|
+
token.attrPush(['src', src]);
|
|
156
|
+
token.attrPush(['service', service]);
|
|
157
|
+
token.attrPush(['url', match[2]]);
|
|
158
|
+
token.level = theState.level;
|
|
159
|
+
}
|
|
160
|
+
theState.pos += theState.src.indexOf(')', theState.pos);
|
|
161
|
+
return true;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { FilterCSS } from 'cssfilter';
|
|
2
|
+
import { escapeAttrValue, FilterXSS, safeAttrValue } from 'xss';
|
|
3
|
+
|
|
4
|
+
const stack = [];
|
|
5
|
+
const voidTags = ['br', 'hr', 'input', 'img', 'link', 'source', 'col', 'area', 'base', 'meta', 'embed', 'param', 'track', 'wbr'];
|
|
6
|
+
const depedentTags = {
|
|
7
|
+
li: ['ul', 'ol'],
|
|
8
|
+
tr: ['table'],
|
|
9
|
+
td: ['tr'],
|
|
10
|
+
th: ['tr'],
|
|
11
|
+
thead: ['table'],
|
|
12
|
+
tbody: ['table'],
|
|
13
|
+
tfoot: ['table'],
|
|
14
|
+
colgroup: ['table'],
|
|
15
|
+
col: ['colgroup'],
|
|
16
|
+
caption: ['table'],
|
|
17
|
+
option: ['select'],
|
|
18
|
+
optgroup: ['select'],
|
|
19
|
+
dt: ['dl'],
|
|
20
|
+
dd: ['dl'],
|
|
21
|
+
};
|
|
22
|
+
const whitelistClasses = ['row', 'columns', 'typo', 'note', 'warn'].concat(Array.from({ length: 12 }).fill(0).map((_, i) => `medium-${i + 1}`));
|
|
23
|
+
|
|
24
|
+
const tagCheck = new FilterXSS({
|
|
25
|
+
css: false,
|
|
26
|
+
whiteList: {},
|
|
27
|
+
onIgnoreTag(tag, html, options) {
|
|
28
|
+
if (html.endsWith('/>') || voidTags.includes(tag)) return html;
|
|
29
|
+
if (!options.isClosing) {
|
|
30
|
+
if (depedentTags[tag] && !stack.find((i) => depedentTags[tag].includes(i))) {
|
|
31
|
+
return html.replace(/</g, '<').replace(/>/g, '>'); // 标签不可出现在该位置
|
|
32
|
+
}
|
|
33
|
+
stack.push(tag);
|
|
34
|
+
return html;
|
|
35
|
+
}
|
|
36
|
+
if (stack.length === 0) {
|
|
37
|
+
return html.replace(/</g, '<').replace(/>/g, '>'); // 没有标签可供闭合
|
|
38
|
+
}
|
|
39
|
+
if (stack[stack.length - 1] === tag) {
|
|
40
|
+
stack.pop(); // 正常关闭
|
|
41
|
+
return html;
|
|
42
|
+
}
|
|
43
|
+
if (stack.length - 2 >= 0 && stack[stack.length - 2] === tag) {
|
|
44
|
+
// 可能丢失了一个结束标签
|
|
45
|
+
html = `</${stack[stack.length - 1]}>${html}`;
|
|
46
|
+
stack.pop();
|
|
47
|
+
stack.pop();
|
|
48
|
+
return html;
|
|
49
|
+
}
|
|
50
|
+
return html.replace(/</g, '<').replace(/>/g, '>'); // 可能多出了一个结束标签
|
|
51
|
+
},
|
|
52
|
+
onIgnoreTagAttr(tag, name, value) {
|
|
53
|
+
return value;
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const cssFilterOptions = {
|
|
58
|
+
whiteList: {
|
|
59
|
+
'font-size': true,
|
|
60
|
+
'font-family': true,
|
|
61
|
+
'text-align': true,
|
|
62
|
+
'text-indent': true,
|
|
63
|
+
'margin-left': true,
|
|
64
|
+
position: /relative/,
|
|
65
|
+
padding: true,
|
|
66
|
+
height: true,
|
|
67
|
+
width: true,
|
|
68
|
+
color: true,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const CssFilter = new FilterCSS(cssFilterOptions);
|
|
73
|
+
|
|
74
|
+
const commonRules = {
|
|
75
|
+
whiteList: {
|
|
76
|
+
a: ['target', 'href', 'title'],
|
|
77
|
+
abbr: ['title'],
|
|
78
|
+
address: [],
|
|
79
|
+
aside: [],
|
|
80
|
+
b: [],
|
|
81
|
+
bdi: ['dir'],
|
|
82
|
+
bdo: ['dir'],
|
|
83
|
+
big: [],
|
|
84
|
+
blockquote: ['cite', 'class'],
|
|
85
|
+
br: [],
|
|
86
|
+
caption: [],
|
|
87
|
+
center: [],
|
|
88
|
+
cite: [],
|
|
89
|
+
code: ['class'],
|
|
90
|
+
del: ['datetime'],
|
|
91
|
+
div: ['id', 'class'],
|
|
92
|
+
dl: [],
|
|
93
|
+
em: [],
|
|
94
|
+
font: ['color', 'size', 'face'],
|
|
95
|
+
header: [],
|
|
96
|
+
i: [],
|
|
97
|
+
ins: ['datetime'],
|
|
98
|
+
mark: [],
|
|
99
|
+
ol: [],
|
|
100
|
+
p: ['align', 'style'],
|
|
101
|
+
pre: [],
|
|
102
|
+
s: [],
|
|
103
|
+
small: [],
|
|
104
|
+
span: ['class', 'style'],
|
|
105
|
+
sub: [],
|
|
106
|
+
sup: [],
|
|
107
|
+
strong: ['id'],
|
|
108
|
+
tt: [],
|
|
109
|
+
u: [],
|
|
110
|
+
var: [],
|
|
111
|
+
},
|
|
112
|
+
css: false,
|
|
113
|
+
allowCommentTag: false,
|
|
114
|
+
stripIgnoreTag: true,
|
|
115
|
+
stripIgnoreTagBody: ['script', 'semantics'],
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const xss = new FilterXSS({
|
|
119
|
+
...commonRules,
|
|
120
|
+
whiteList: {
|
|
121
|
+
...commonRules.whiteList,
|
|
122
|
+
area: ['shape', 'coords', 'href', 'alt'],
|
|
123
|
+
article: [],
|
|
124
|
+
audio: ['controls', 'loop', 'preload', 'src'],
|
|
125
|
+
col: ['align', 'valign', 'span', 'width'],
|
|
126
|
+
colgroup: ['align', 'valign', 'span', 'width'],
|
|
127
|
+
dd: [],
|
|
128
|
+
details: ['open'],
|
|
129
|
+
dt: [],
|
|
130
|
+
h1: ['id'],
|
|
131
|
+
h2: ['id', 'class'],
|
|
132
|
+
h3: ['id'],
|
|
133
|
+
h4: ['id'],
|
|
134
|
+
h5: ['id'],
|
|
135
|
+
h6: ['id'],
|
|
136
|
+
hr: [],
|
|
137
|
+
img: ['src', 'alt', 'title', 'width', 'height'],
|
|
138
|
+
li: [],
|
|
139
|
+
section: [],
|
|
140
|
+
summary: [],
|
|
141
|
+
table: ['width', 'border', 'align', 'valign'],
|
|
142
|
+
tbody: ['align', 'valign'],
|
|
143
|
+
td: ['width', 'rowspan', 'colspan', 'align', 'valign', 'bgcolor'],
|
|
144
|
+
tfoot: ['align', 'valign'],
|
|
145
|
+
th: ['width', 'rowspan', 'colspan', 'align', 'valign'],
|
|
146
|
+
thead: ['align', 'valign'],
|
|
147
|
+
tr: ['rowspan', 'align', 'valign'],
|
|
148
|
+
ul: [],
|
|
149
|
+
video: ['controls', 'loop', 'preload', 'src', 'height', 'width'],
|
|
150
|
+
},
|
|
151
|
+
css: cssFilterOptions,
|
|
152
|
+
safeAttrValue(tag, name, value) {
|
|
153
|
+
if (name === 'id') return escapeAttrValue(`xss-id-${value}`);
|
|
154
|
+
if (name === 'class') return value.split(' ').filter((i) => whitelistClasses.includes(i) || i.startsWith('language-')).join(' ');
|
|
155
|
+
return safeAttrValue(tag, name, value, CssFilter);
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const inlineCssFilter = new FilterCSS({
|
|
160
|
+
whiteList: {
|
|
161
|
+
color: true,
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
export const xssInline = new FilterXSS({
|
|
166
|
+
...commonRules,
|
|
167
|
+
safeAttrValue(tag, name, value) {
|
|
168
|
+
if (name === 'id') return escapeAttrValue(`xss-id-${value}`);
|
|
169
|
+
if (name === 'class') return value.split(' ').filter((i) => whitelistClasses.includes(i)).join(' ');
|
|
170
|
+
return safeAttrValue(tag, name, value, inlineCssFilter);
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
export function ensureTag(html: string) {
|
|
175
|
+
stack.length = 0;
|
|
176
|
+
const res = tagCheck.process(html);
|
|
177
|
+
return res + stack.map((i) => `</${i}>`).join('');
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function xssProtector(md) {
|
|
181
|
+
function protector(state) {
|
|
182
|
+
const processor = state.inlineMode ? xssInline : xss;
|
|
183
|
+
for (let i = 0; i < state.tokens.length; i++) {
|
|
184
|
+
const cur = state.tokens[i];
|
|
185
|
+
if (cur.type === 'html_block') {
|
|
186
|
+
cur.content = processor.process(cur.content);
|
|
187
|
+
}
|
|
188
|
+
if (cur.type === 'inline') {
|
|
189
|
+
const inlineTokens = cur.children;
|
|
190
|
+
for (let ii = 0; ii < inlineTokens.length; ii++) {
|
|
191
|
+
if (inlineTokens[ii].type === 'html_inline') {
|
|
192
|
+
inlineTokens[ii].content = processor.process(inlineTokens[ii].content);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
md.core.ruler.after('linkify', 'xss', protector);
|
|
200
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const MarkdownIt = require('markdown-it');
|
|
2
|
+
|
|
3
|
+
// For math: $a\times b\eq 10$
|
|
4
|
+
// Specific image size: 
|
|
5
|
+
const Imsize = require('markdown-it-imsize');
|
|
6
|
+
/* Footnote support.
|
|
7
|
+
Here is a footnote reference,[^1] and another.[^longnote]
|
|
8
|
+
|
|
9
|
+
[^1]: Here is the footnote.
|
|
10
|
+
|
|
11
|
+
[^longnote]: Here's one with multiple blocks.
|
|
12
|
+
|
|
13
|
+
Subsequent paragraphs are indented to show that they
|
|
14
|
+
belong to the previous footnote.
|
|
15
|
+
*/
|
|
16
|
+
const Footnote = require('markdown-it-footnote');
|
|
17
|
+
// ==Highlight==
|
|
18
|
+
const Mark = require('markdown-it-mark');
|
|
19
|
+
const TOC = require('markdown-it-table-of-contents');
|
|
20
|
+
const Anchor = require('markdown-it-anchor');
|
|
21
|
+
const MergeCells = require('markdown-it-merge-cells');
|
|
22
|
+
// @[url](videourl)
|
|
23
|
+
// @[youtube](https://youtube.com/watch?v=xxx)
|
|
24
|
+
// @[pdf](https://foo.com/bar.pdf)
|
|
25
|
+
const { Media } = require('./markdown-it-media');
|
|
26
|
+
const { default: Katex } = require('./markdown-it-katex');
|
|
27
|
+
const { xssProtector } = require('./markdown-it-xss');
|
|
28
|
+
|
|
29
|
+
class Markdown extends MarkdownIt {
|
|
30
|
+
constructor() {
|
|
31
|
+
super({
|
|
32
|
+
linkify: true,
|
|
33
|
+
html: true,
|
|
34
|
+
});
|
|
35
|
+
this.linkify.tlds('.py', false);
|
|
36
|
+
this.use(Media);
|
|
37
|
+
this.use(Imsize);
|
|
38
|
+
this.use(Footnote);
|
|
39
|
+
this.use(Mark);
|
|
40
|
+
this.use(Anchor);
|
|
41
|
+
this.use(TOC);
|
|
42
|
+
this.use(Katex);
|
|
43
|
+
this.use(MergeCells);
|
|
44
|
+
this.use(xssProtector);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const md = new Markdown();
|
|
49
|
+
|
|
50
|
+
function plugin(func, ...args) {
|
|
51
|
+
md.use(func, ...args);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function render(text) {
|
|
55
|
+
return md.render(text);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function renderInline(text) {
|
|
59
|
+
return md.renderInline(text);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = {
|
|
63
|
+
md, plugin, render, renderInline,
|
|
64
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { moment, ObjectId } from 'hydrooj';
|
|
2
|
+
import { AnsiUp } from 'ansi_up';
|
|
3
|
+
|
|
4
|
+
export { formatSeconds, size } from 'hydrooj';
|
|
5
|
+
|
|
6
|
+
const AU = new AnsiUp();
|
|
7
|
+
|
|
8
|
+
export function ansiToHtml(str: string, whiteToBlack = true) {
|
|
9
|
+
const res = AU.ansi_to_html(str);
|
|
10
|
+
return whiteToBlack ? res.replace(/style="color:rgb\(255,255,255\)"/g, 'style="color:black"') : res;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function datetimeSpan(dt: Date | ObjectId, relative = true, format = 'YYYY-M-D H:mm:ss', tz = 'Asia/Shanghai') {
|
|
14
|
+
if (!dt) return 'DATETIME_SPAN_ERROR';
|
|
15
|
+
if (dt instanceof ObjectId) dt = dt.getTimestamp();
|
|
16
|
+
else if (typeof dt === 'string' && ObjectId.isValid(dt)) dt = new ObjectId(dt).getTimestamp();
|
|
17
|
+
else if (typeof dt === 'number' || typeof dt === 'string') dt = new Date(dt);
|
|
18
|
+
return '<span class="time{0}" data-timestamp="{1}">{2}</span>'.format(
|
|
19
|
+
relative ? ' relative' : '',
|
|
20
|
+
dt.getTime() / 1000,
|
|
21
|
+
moment(dt).tz(tz).format(format),
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function* paginate(page: number, numPages: number) {
|
|
26
|
+
const radius = 5;
|
|
27
|
+
let first: number;
|
|
28
|
+
let last: number;
|
|
29
|
+
if (page > 1) {
|
|
30
|
+
if (page > 2) yield ['first', 1];
|
|
31
|
+
yield ['previous', page - 1];
|
|
32
|
+
}
|
|
33
|
+
if (page <= radius) [first, last] = [1, Math.min(1 + radius * 2, numPages)];
|
|
34
|
+
else if (page >= numPages - radius) {
|
|
35
|
+
[first, last] = [Math.max(1, numPages - radius * 2), numPages];
|
|
36
|
+
} else {
|
|
37
|
+
[first, last] = [page - radius, page + radius];
|
|
38
|
+
}
|
|
39
|
+
if (first > 1) yield ['ellipsis', 0];
|
|
40
|
+
for (let page0 = first; page0 < last + 1; page0++) {
|
|
41
|
+
if (page0 !== page) yield ['page', page0];
|
|
42
|
+
else yield ['current', page];
|
|
43
|
+
}
|
|
44
|
+
if (last < numPages) yield ['ellipsis', 0];
|
|
45
|
+
if (page < numPages) {
|
|
46
|
+
yield ['next', page + 1];
|
|
47
|
+
if (page < numPages - 1) yield ['last', numPages];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function buildQueryString(obj: Record<string, any>) {
|
|
52
|
+
return Object.entries(obj).filter(([key, value]) => value && !key.startsWith('__'))
|
|
53
|
+
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join('&');
|
|
54
|
+
}
|