Skip to content

Commit bc76022

Browse files
committed
Fix #91 && add more contentInfo supports
Add support for loading previews in `contentInfo`. Such as `PageTitle` and `ContentModel`.
1 parent aef527e commit bc76022

File tree

3 files changed

+717
-496
lines changed

3 files changed

+717
-496
lines changed

snippets/snippets.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ pageInfo:
9191
PageTitle=#${2:}#
9292
PageID=#${3:}#
9393
RevisionID=#${4:}#
94-
ContentModel=#${5:}#
95-
ContentFormat=#${6:}#
94+
ContentModel=#${5:wikitext}#
95+
ContentFormat=#${6:text/x-wiki}#
9696
[END_PAGE_INFO] --%>
9797
description: Page Info Struct
9898
refName:

src/export_command/wikimedia_function/view.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { showMWErrorMessage } from './err_msg';
1717
*/
1818
let previewCurrentPanel: vscode.WebviewPanel | undefined;
1919

20-
export function getPageViewFactory(){
20+
export function getPageViewFactory() {
2121
return async function getPageView(): Promise<void> {
2222
const config: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("wikitext");
2323

@@ -65,19 +65,20 @@ export function getPreviewFactory(extension: vscode.ExtensionContext) {
6565
/** document text */
6666
const sourceText: string | undefined = vscode.window.activeTextEditor?.document.getText();
6767
if (!sourceText) { return undefined; }
68-
const { content } = getContentInfo(sourceText);
68+
const contentInfo = getContentInfo(sourceText);
6969

7070
/** arguments */
71-
const args: Record<string, string> = {
71+
const args: Record<string, string | undefined> = {
7272
'action': Action.parse,
73-
'text': content,
73+
'text': contentInfo.content,
74+
'title': !(contentInfo.info?.pageTitle) ? undefined : contentInfo.info.pageTitle,
7475
'prop': alterNativeValues(
7576
Prop.text,
7677
Prop.displayTitle,
7778
Prop.categoriesHTML,
7879
(config.get("getCss") ? Prop.headHTML : undefined)
7980
),
80-
'contentmodel': ContextModel.wikitext,
81+
'contentmodel': !(contentInfo.info?.contentModel) ? ContextModel.wikitext : contentInfo.info.contentModel,
8182
'pst': "why_not",
8283
'disableeditsection': "yes"
8384
};
@@ -117,7 +118,7 @@ export function getPreviewFactory(extension: vscode.ExtensionContext) {
117118
* @param baseURI url base
118119
* @returns task
119120
*/
120-
export async function showViewer(currentPanel: vscode.WebviewPanel | string, viewerTitle: string, args: Record<string, string>, tBot: MWBot, baseURI: string): Promise<void> {
121+
export async function showViewer(currentPanel: vscode.WebviewPanel | string, viewerTitle: string, args: Record<string, string | undefined>, tBot: MWBot, baseURI: string): Promise<void> {
121122
const config: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("wikitext");
122123

123124
const barMessage: vscode.Disposable = vscode.window.setStatusBarMessage("Wikitext: Getting view...");

0 commit comments

Comments
 (0)