Skip to content

Commit f5529f9

Browse files
feat(#70): Github Alerts (#72)
* feat(#70): Add GitHub alerts transformation to Confluence macros --------- Co-authored-by: frankledo <[email protected]> Co-authored-by: Frank Ledo <[email protected]>
1 parent 144d4ed commit f5529f9

File tree

12 files changed

+896
-6
lines changed

12 files changed

+896
-6
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
blockquotes

components/markdown-confluence-sync/CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
#### Deprecated
1212
#### Removed
1313

14-
## Unreleased
14+
## [2.4.0] - 2025-11-27
1515

1616
#### Added
1717

18+
* feat(#70): Add GitHub alerts transformation to Confluence macros.
19+
GitHub-flavored markdown alerts ([!NOTE], [!TIP], [!IMPORTANT],
20+
[!WARNING], [!CAUTION]) are now converted to Confluence's native
21+
info, note, warning, and tip macros. This feature is disabled by
22+
default and can be enabled via `rehype.alerts` configuration option.
23+
1824
## [2.3.0] - 2025-11-24
1925

2026
#### Added

components/markdown-confluence-sync/README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ The namespace for the configuration of this library is `markdown-confluence-sync
303303
| `confluence.noticeTemplate` | `string` | Template string to use for the notice message. | |
304304
| `confluence.dryRun` | `boolean` | Log create, update or delete requests to Confluence instead of really making them | `false` |
305305
| `rehype.codeBlocks` | `boolean` | Enable conversion of code blocks to Confluence code macro format with syntax highlighting. When disabled, code blocks remain as plain HTML pre/code tags. | `false` |
306+
| `rehype.githubAlerts` | `boolean` | Enable conversion of GitHub alerts ([!NOTE], [!TIP], [!IMPORTANT], [!WARNING], [!CAUTION]) to Confluence info/note/warning/tip macros. When disabled, github alerts remain as blockquotes. | `false` |
306307
| `dryRun` | `boolean` | Process markdown files without sending them to `confluence-sync`. Useful to early detection of possible errors in configuration, etc. Note that, requests that would be made to Confluence won't be logged, use `confluence.dryRun` for that, which also connects to Confluence to calculate the requests to do | `false` |
307308
| `config.readArguments` | `boolean` | Read configuration from arguments or not | `false` |
308309
| `config.readFile` | `boolean` | Read configuration from file or not | `false` |
@@ -495,7 +496,7 @@ Apart of supporting the most common markdown features, the library also supports
495496
<ac:rich-text-body><p>This is the content of the details.</p></ac:rich-text-body>
496497
</ac:structured-macro>
497498
```
498-
* Code blocks - Markdown fenced code blocks can be converted to
499+
* [Code blocks](https://www.markdownguide.org/extended-syntax/#fenced-code-blocks) - Markdown fenced code blocks can be converted to
499500
Confluence code macro format with syntax highlighting support. This
500501
feature is disabled by default but can be enabled via the
501502
`rehype.codeBlocks` configuration option.
@@ -519,6 +520,33 @@ Apart of supporting the most common markdown features, the library also supports
519520
<ac:plain-text-body><![ CDATA [ const hello = "world";console.log(hello);] ]></ac:plain-text-body>
520521
</ac:structured-macro>
521522
```
523+
* [GitHub Alerts](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts) - GitHub-flavored markdown alerts can be converted to
524+
Confluence's native info, note, warning, and tip macros. This feature
525+
is disabled by default but can be enabled via the `rehype.githubAlerts`
526+
configuration option.
527+
* The plugin converts GitHub alert syntax (`[!NOTE]`, `[!TIP]`,
528+
`[!IMPORTANT]`, `[!WARNING]`, `[!CAUTION]`) to appropriate
529+
Confluence macros.
530+
* Alert content including formatted text, code, and lists is
531+
preserved in the conversion.
532+
* This feature is disabled by default for backward compatibility.
533+
Enable it by setting `rehype.githubAlerts: true`.
534+
* For example, the following markdown alert:
535+
```markdown
536+
> [!NOTE]
537+
> Useful information that users should know, even when skimming
538+
> content.
539+
```
540+
will be converted to a Confluence info macro as follows:
541+
```markdown
542+
<ac:structured-macro ac:name="info">
543+
<ac:parameter ac:name="title">Note</ac:parameter>
544+
<ac:rich-text-body>
545+
<p>Useful information that users should know, even when skimming
546+
content.</p>
547+
</ac:rich-text-body>
548+
</ac:structured-macro>
549+
```
522550
523551
### Unsupported features
524552

components/markdown-confluence-sync/markdown-confluence-sync.config.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ module.exports = {
4343
logLevel: "debug",
4444
rehype: {
4545
codeBlocks: true,
46+
githubAlerts: true,
4647
},
4748
};

components/markdown-confluence-sync/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@telefonica/markdown-confluence-sync",
33
"description": "Creates/updates/deletes Confluence pages based on markdown files in a directory. Supports Mermaid diagrams and per-page configuration using frontmatter metadata. Works great with Docusaurus",
4-
"version": "2.3.0",
4+
"version": "2.4.0",
55
"license": "Apache-2.0",
66
"author": "Telefónica Innovación Digital",
77
"repository": {

components/markdown-confluence-sync/src/lib/confluence/ConfluenceSync.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import type {
3636
AuthenticationOption,
3737
RehypeCodeBlocksOptionDefinition,
3838
RehypeCodeBlocksOption,
39+
RehypeGithubAlertsOptionDefinition,
40+
RehypeGithubAlertsOption,
3941
ApiPrefixOption,
4042
ApiPrefixOptionDefinition,
4143
} from "./ConfluenceSync.types.js";
@@ -101,6 +103,12 @@ const rehypeCodeBlocksOption: RehypeCodeBlocksOptionDefinition = {
101103
default: false,
102104
};
103105

106+
const rehypeGithubAlertsOption: RehypeGithubAlertsOptionDefinition = {
107+
name: "githubAlerts",
108+
type: "boolean",
109+
default: false,
110+
};
111+
104112
export const ConfluenceSync: ConfluenceSyncConstructor = class ConfluenceSync
105113
implements ConfluenceSyncInterface
106114
{
@@ -120,6 +128,7 @@ export const ConfluenceSync: ConfluenceSyncConstructor = class ConfluenceSync
120128
private _logger: LoggerInterface;
121129
private _modeOption: ModeOption;
122130
private _rehypeCodeBlocksOption: RehypeCodeBlocksOption;
131+
private _rehypeGithubAlertsOption: RehypeGithubAlertsOption;
123132

124133
constructor({ config, rehypeConfig, logger, mode }: ConfluenceSyncOptions) {
125134
this._urlOption = config.addOption(urlOption) as UrlOption;
@@ -151,6 +160,10 @@ export const ConfluenceSync: ConfluenceSyncConstructor = class ConfluenceSync
151160
rehypeCodeBlocksOption,
152161
) as RehypeCodeBlocksOption;
153162

163+
this._rehypeGithubAlertsOption = rehypeConfig.addOption(
164+
rehypeGithubAlertsOption,
165+
) as RehypeGithubAlertsOption;
166+
154167
this._modeOption = mode;
155168
this._logger = logger;
156169
}
@@ -220,6 +233,7 @@ export const ConfluenceSync: ConfluenceSyncConstructor = class ConfluenceSync
220233
logger: this._logger.namespace("transformer"),
221234
rehype: {
222235
codeBlocks: this._rehypeCodeBlocksOption.value,
236+
githubAlerts: this._rehypeGithubAlertsOption.value,
223237
},
224238
});
225239

components/markdown-confluence-sync/src/lib/confluence/ConfluenceSync.types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type NoticeTemplateOptionValue = string;
2525
type DryRunOptionValue = boolean;
2626

2727
type RehypeCodeBlocksOptionValue = boolean;
28+
type RehypeGithubAlertsOptionValue = boolean;
2829

2930
declare global {
3031
//eslint-disable-next-line @typescript-eslint/no-namespace
@@ -58,6 +59,8 @@ declare global {
5859
rehype?: {
5960
/** Enable code blocks transformation to Confluence code macro */
6061
codeBlocks?: RehypeCodeBlocksOptionValue;
62+
/** Enable GitHub alerts transformation to Confluence info/note/warning/tip macros */
63+
githubAlerts?: RehypeGithubAlertsOptionValue;
6164
};
6265
}
6366
}
@@ -82,6 +85,8 @@ export type DryRunOptionDefinition = OptionDefinition<
8285
>;
8386
export type RehypeCodeBlocksOptionDefinition =
8487
OptionDefinition<RehypeCodeBlocksOptionValue>;
88+
export type RehypeGithubAlertsOptionDefinition =
89+
OptionDefinition<RehypeGithubAlertsOptionValue>;
8590

8691
export type AuthenticationOptionDefinition =
8792
OptionDefinition<ConfluenceClientAuthenticationConfig>;
@@ -109,6 +114,11 @@ export type RehypeCodeBlocksOption = OptionInterfaceOfType<
109114
{ hasDefault: true }
110115
>;
111116

117+
export type RehypeGithubAlertsOption = OptionInterfaceOfType<
118+
RehypeGithubAlertsOptionValue,
119+
{ hasDefault: true }
120+
>;
121+
112122
export interface ConfluenceSyncOptions {
113123
/** Configuration interface */
114124
config: ConfigNamespaceInterface;

components/markdown-confluence-sync/src/lib/confluence/transformer/ConfluencePageTransformer.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { InvalidTemplateError } from "./errors/InvalidTemplateError.js";
2727
import rehypeAddAttachmentsImages from "./support/rehype/rehype-add-attachments-images.js";
2828
import type { ImagesMetadata } from "./support/rehype/rehype-add-attachments-images.types.js";
2929
import rehypeAddNotice from "./support/rehype/rehype-add-notice.js";
30+
import rehypeReplaceGithubAlerts from "./support/rehype/rehype-replace-github-alerts.js";
3031
import rehypeReplaceCodeBlocks from "./support/rehype/rehype-replace-code-blocks.js";
3132
import rehypeReplaceDetails from "./support/rehype/rehype-replace-details.js";
3233
import rehypeReplaceImgTags from "./support/rehype/rehype-replace-img-tags.js";
@@ -52,14 +53,15 @@ export const ConfluencePageTransformer: ConfluencePageTransformerConstructor = c
5253
private readonly _spaceKey: string;
5354
private readonly _logger?: LoggerInterface;
5455
private readonly _rehypeCodeBlocksEnabled: boolean;
56+
private readonly _rehypeGithubAlertsEnabled: boolean;
5557

5658
constructor({
5759
noticeMessage,
5860
noticeTemplate,
5961
rootPageName,
6062
spaceKey,
6163
logger,
62-
rehype: { codeBlocks },
64+
rehype: { codeBlocks, githubAlerts },
6365
}: ConfluencePageTransformerOptions) {
6466
this._noticeMessage = noticeMessage;
6567
this._noticeTemplateRaw = noticeTemplate;
@@ -70,9 +72,10 @@ export const ConfluencePageTransformer: ConfluencePageTransformerConstructor = c
7072
this._spaceKey = spaceKey;
7173
this._logger = logger;
7274
this._rehypeCodeBlocksEnabled = codeBlocks ?? false;
75+
this._rehypeGithubAlertsEnabled = githubAlerts ?? false;
7376

7477
logger?.debug(
75-
`ConfluencePageTransformer initialized with rehype options: ${JSON.stringify({ codeBlocks: this._rehypeCodeBlocksEnabled })}`,
78+
`ConfluencePageTransformer initialized with rehype options: ${JSON.stringify({ codeBlocks: this._rehypeCodeBlocksEnabled, alerts: this._rehypeGithubAlertsEnabled })}`,
7679
);
7780
}
7881

@@ -117,6 +120,12 @@ export const ConfluencePageTransformer: ConfluencePageTransformerConstructor = c
117120
processor = processor.use(rehypeReplaceCodeBlocks);
118121
}
119122

123+
// Conditionally add alerts plugin
124+
if (this._rehypeGithubAlertsEnabled) {
125+
this._logger?.debug(`Registering rehypeReplaceAlerts plugin`);
126+
processor = processor.use(rehypeReplaceGithubAlerts);
127+
}
128+
120129
const content = processor
121130
.use(rehypeAddAttachmentsImages)
122131
.use(rehypeReplaceImgTags)

components/markdown-confluence-sync/src/lib/confluence/transformer/ConfluencePageTransformer.types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ export interface ConfluencePageTransformerRehypeOptions {
1818
* @default false
1919
*/
2020
codeBlocks?: boolean;
21+
/**
22+
* Enable GitHub alerts transformation to Confluence info/note/warning/tip macros.
23+
* When enabled, GitHub-flavored markdown alerts (e.g., [!NOTE], [!WARNING])
24+
* will be converted to appropriate Confluence macro format.
25+
* When this option is not specified or set to false, alerts will remain as blockquotes.
26+
* @default false
27+
*/
28+
githubAlerts?: boolean;
2129
}
2230

2331
export interface ConfluencePageTransformerOptions {

0 commit comments

Comments
 (0)