Skip to content

Commit

Permalink
Fix #91 && add more contentInfo supports
Browse files Browse the repository at this point in the history
Add support for loading previews in `contentInfo`. Such as `PageTitle` and `ContentModel`.
  • Loading branch information
Frederisk committed Aug 1, 2024
1 parent aef527e commit bc76022
Show file tree
Hide file tree
Showing 3 changed files with 717 additions and 496 deletions.
4 changes: 2 additions & 2 deletions snippets/snippets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ pageInfo:
PageTitle=#${2:}#
PageID=#${3:}#
RevisionID=#${4:}#
ContentModel=#${5:}#
ContentFormat=#${6:}#
ContentModel=#${5:wikitext}#
ContentFormat=#${6:text/x-wiki}#
[END_PAGE_INFO] --%>
description: Page Info Struct
refName:
Expand Down
13 changes: 7 additions & 6 deletions src/export_command/wikimedia_function/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { showMWErrorMessage } from './err_msg';
*/
let previewCurrentPanel: vscode.WebviewPanel | undefined;

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

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

/** arguments */
const args: Record<string, string> = {
const args: Record<string, string | undefined> = {
'action': Action.parse,
'text': content,
'text': contentInfo.content,
'title': !(contentInfo.info?.pageTitle) ? undefined : contentInfo.info.pageTitle,
'prop': alterNativeValues(
Prop.text,
Prop.displayTitle,
Prop.categoriesHTML,
(config.get("getCss") ? Prop.headHTML : undefined)
),
'contentmodel': ContextModel.wikitext,
'contentmodel': !(contentInfo.info?.contentModel) ? ContextModel.wikitext : contentInfo.info.contentModel,
'pst': "why_not",
'disableeditsection': "yes"
};
Expand Down Expand Up @@ -117,7 +118,7 @@ export function getPreviewFactory(extension: vscode.ExtensionContext) {
* @param baseURI url base
* @returns task
*/
export async function showViewer(currentPanel: vscode.WebviewPanel | string, viewerTitle: string, args: Record<string, string>, tBot: MWBot, baseURI: string): Promise<void> {
export async function showViewer(currentPanel: vscode.WebviewPanel | string, viewerTitle: string, args: Record<string, string | undefined>, tBot: MWBot, baseURI: string): Promise<void> {
const config: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("wikitext");

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

0 comments on commit bc76022

Please sign in to comment.