Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implemented italic and bolt options #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ado-manifests/azure-devops-extension-test.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "banner-settings-hub-improved-test",
"name": "Banner Settings (Test)",
"version": "1.0.75",
"version": "1.0.76",
"publisher": "razorspoint",
"public": false,
"contributions": [
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 26 additions & 7 deletions src/models/global-message-banners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@

/* tslint:disable:max-classes-per-file */

const markdownLinkRegex = /\[([^[\]]+)\]\(([^()]+)\)/g;
const aTagLinkRegex = /<a href=["']([^<>]+)["']>([^<>]+)<\/a>/g;
const toHtmlConfigs: ReplacementConfig[] = [

Check failure on line 6 in src/models/global-message-banners.ts

View workflow job for this annotation

GitHub Actions / build

'toHtmlConfigs' is assigned a value but never used
{ regex: /\*\*([^\*\*]+)\*\*/g, replaceWith: "<strong>$1</strong>" }, // Bold

Check failure on line 7 in src/models/global-message-banners.ts

View workflow job for this annotation

GitHub Actions / build

Unnecessary escape character: \*

Check failure on line 7 in src/models/global-message-banners.ts

View workflow job for this annotation

GitHub Actions / build

Unnecessary escape character: \*
{ regex: /\*([^\*]+)\*/g, replaceWith: "<em>$1</em>" }, // Italic

Check failure on line 8 in src/models/global-message-banners.ts

View workflow job for this annotation

GitHub Actions / build

Unnecessary escape character: \*
{ regex: /\[([^[\]]+)\]\(([^()]+)\)/g, replaceWith: "<a href='$2'>$1</a>" } // Links
];

const toMarkdownConfigs: ReplacementConfig[] = [
{ regex: /<strong>([^<]+)<\/strong>/g, replaceWith: "**$1**" }, // Bold
{ regex: /<em>([^<]+)<\/em>/g, replaceWith: "*$1*" }, // Italic
{ regex: /<a href=["']([^<>]+)["']>([^<>]+)<\/a>/g, replaceWith: "[$2]($1)" } // Links
];

export enum Priority {
p0, p1, p2,
Expand All @@ -14,6 +23,12 @@
Info, Warning, Error,
}

// Define a configuration interface for replacements
interface ReplacementConfig {
regex: RegExp;
replaceWith: string;
}

export class GlobalMessageBanner {
public priority: Priority;
public level: Level;
Expand Down Expand Up @@ -45,21 +60,25 @@
const body = entity.value[title];
banner.priority = Priority[title.slice(0, 2)];
banner.messageId = title.slice(3);
banner.message = body.message.replace(aTagLinkRegex, `[$2]($1)`);
banner.message = this.replaceMultipleFormats(body.message, toMarkdownConfigs),
banner.level = Level[this.fixTypeCase(body.level)];
banner.expirationDate = body.expirationDate != null ? new Date(body.expirationDate) : null;
bannerList.push(banner);
});
return bannerList;
}

public toWebEntity(): {[name: string]: WebGlobalMessageBanner} {
const ret: {[name: string]: WebGlobalMessageBanner} = {};
public static replaceMultipleFormats(message: string, configs: ReplacementConfig[]): string {
return configs.reduce((acc, config) => acc.replace(config.regex, config.replaceWith), message);
}

public toWebEntity(): { [name: string]: WebGlobalMessageBanner } {
const ret: { [name: string]: WebGlobalMessageBanner } = {};
const title = `GlobalMessageBanners/${Priority[this.priority]}-${this.messageId}`;

ret[title] = {
level: Level[this.level],
message: this.message.replace(markdownLinkRegex, `<a href='$2'>$1</a>`),
message: GlobalMessageBanner.replaceMultipleFormats(this.message, toMarkdownConfigs),
};

if (this.expirationDate != null) {
Expand All @@ -79,5 +98,5 @@

export class ObjectListWithCount<T> {
public count: number;
public value: {[name: string]: T};
public value: { [name: string]: T };
}
Loading