-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
869b97a
commit e52b174
Showing
3 changed files
with
125 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const licenses = { | ||
// Apache | ||
"REWRITE_LICENSE_LINK": "[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)", | ||
"REWRITE_OPENAPI_LICENSE_LINK": "[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)", | ||
"REWRITE_MICRONAUT_LICENSE_LINK": "[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)", | ||
"REWRITE_GRADLE_TOOLING_MODEL_LICENSE_LINK": "[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)", // ? | ||
"REWRITE_JAVA_DEPENDENCIES_LICENSE_LINK": "[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)", | ||
"REWRITE_ALL_LICENSE_LINK": "[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)", | ||
"REWRITE_BUILD_GRADLE_PLUGIN_LICENSE_LINK": "[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)", // ? | ||
"REWRITE_LIBERTY_LICENSE_LINK": "[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)", | ||
"REWRITE_QUARKUS_LICENSE_LINK": "[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)", | ||
"REWRITE_ANALYSIS_LICENSE_LINK": "[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)", | ||
"REWRITE_TEMPLATING_LICENSE_LINK": "[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)", | ||
"REWRITE_THIRD_PARTY_LICENSE_LINK": "[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)", | ||
"REWRITE_KOTLIN_LICENSE_LINK": "[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)", | ||
|
||
// Moderne Source Available | ||
"REWRITE_GRADLE_PLUGIN_LICENSE_LINK": "[Moderne Source Available License](https://docs.moderne.io/licensing/moderne-source-available-license/)", | ||
"REWRITE_MAVEN_PLUGIN_LICENSE_LINK": "[Moderne Source Available License](https://docs.moderne.io/licensing/moderne-source-available-license/)", | ||
"REWRITE_SPRING_LICENSE_LINK": "[Moderne Source Available License](https://docs.moderne.io/licensing/moderne-source-available-license/)", | ||
"REWRITE_LOGGING_FRAMEWORKS_LICENSE_LINK": "[Moderne Source Available License](https://docs.moderne.io/licensing/moderne-source-available-license/)", | ||
"REWRITE_MIGRATE_JAVA_LICENSE_LINK": "[Moderne Source Available License](https://docs.moderne.io/licensing/moderne-source-available-license/)", | ||
"REWRITE_STATIC_ANALYSIS_LICENSE_LINK": "[Moderne Source Available License](https://docs.moderne.io/licensing/moderne-source-available-license/)", | ||
"REWRITE_STRUTS_LICENSE_LINK": "[Moderne Source Available License](https://docs.moderne.io/licensing/moderne-source-available-license/)", | ||
"REWRITE_TESTING_FRAMEWORKS_LICENSE_LINK": "[Moderne Source Available License](https://docs.moderne.io/licensing/moderne-source-available-license/)", | ||
"REWRITE_OKHTTP_LICENSE_LINK": "[Moderne Source Available License](https://docs.moderne.io/licensing/moderne-source-available-license/)", | ||
"REWRITE_JENKINS_LICENSE_LINK": "[Moderne Source Available License](https://docs.moderne.io/licensing/moderne-source-available-license/)", | ||
"REWRITE_APACHE_LICENSE_LINK": "[Moderne Source Available License](https://docs.moderne.io/licensing/moderne-source-available-license/)", | ||
"REWRITE_MICROMETER_LICENSE_LINK": "[Moderne Source Available License](https://docs.moderne.io/licensing/moderne-source-available-license/)", | ||
"REWRITE_DOCKER_LICENSE_LINK": "[Moderne Source Available License](https://docs.moderne.io/licensing/moderne-source-available-license/)", | ||
"REWRITE_HIBERNATE_LICENSE_LINK": "[Moderne Source Available License](https://docs.moderne.io/licensing/moderne-source-available-license/)", | ||
"REWRITE_CUCUMBER_JVM_LICENSE_LINK": "[Moderne Source Available License](https://docs.moderne.io/licensing/moderne-source-available-license/)", | ||
"REWRITE_FEATURE_FLAGS_LICENSE_LINK": "[Moderne Source Available License](https://docs.moderne.io/licensing/moderne-source-available-license/)", | ||
"REWRITE_GITLAB_LICENSE_LINK": "[Moderne Source Available License](https://docs.moderne.io/licensing/moderne-source-available-license/)", | ||
|
||
// Moderne Proprietary License | ||
"REWRITE_LANGUAGE_LICENSE_LINK": "[Moderne Proprietary License](https://docs.moderne.io/licensing/overview/)", // ? | ||
"REWRITE_CODEMODS_NG_LICENSE_LINK": "[Moderne Proprietary License](https://docs.moderne.io/licensing/overview/)", | ||
"REWRITE_SQL_LICENSE_LINK": "[Moderne Proprietary License](https://docs.moderne.io/licensing/overview/)", | ||
"REWRITE_CIRCLECI_LICENSE_LINK": "[Moderne Proprietary License](https://docs.moderne.io/licensing/overview/)", | ||
"REWRITE_JAVA_SECURITY_LICENSE_LINK": "[Moderne Proprietary License](https://docs.moderne.io/licensing/overview/)", | ||
"REWRITE_NODEJS_LICENSE_LINK": "[Moderne Proprietary License](https://docs.moderne.io/licensing/overview/)", | ||
"REWRITE_AI_SEARCH_LICENSE_LINK": "[Moderne Proprietary License](https://docs.moderne.io/licensing/overview/)", | ||
"REWRITE_GITHUB_ACTIONS_LICENSE_LINK": "[Moderne Proprietary License](https://docs.moderne.io/licensing/overview/)", | ||
"REWRITE_POLYGLOT_LICENSE_LINK": "[Moderne Proprietary License](https://docs.moderne.io/licensing/overview/)", // ? | ||
"REWRITE_TERRAFORM_LICENSE_LINK": "[Moderne Proprietary License](https://docs.moderne.io/licensing/overview/)", | ||
"REWRITE_ANDROID_LICENSE_LINK": "[Moderne Proprietary License](https://docs.moderne.io/licensing/overview/)", | ||
"REWRITE_CONCOURSE_LICENSE_LINK": "[Moderne Proprietary License](https://docs.moderne.io/licensing/overview/)", | ||
"REWRITE_REACTIVE_STREAMS_LICENSE_LINK": "[Moderne Proprietary License](https://docs.moderne.io/licensing/overview/)", | ||
"REWRITE_MIGRATE_PYTHON_LICENSE_LINK": "[Moderne Proprietary License](https://docs.moderne.io/licensing/overview/)", // ? | ||
"REWRITE_KUBERNETES_LICENSE_LINK": "[Moderne Proprietary License](https://docs.moderne.io/licensing/overview/)", | ||
"REWRITE_JACKSON_LICENSE_LINK": "[Moderne Proprietary License](https://docs.moderne.io/licensing/overview/)", | ||
"REWRITE_CODEMODS_LICENSE_LINK": "[Moderne Proprietary License](https://docs.moderne.io/licensing/overview/)", | ||
"REWRITE_DOTNET_LICENSE_LINK": "[Moderne Proprietary License](https://docs.moderne.io/licensing/overview/)", | ||
}; | ||
|
||
export default licenses; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,79 @@ | ||
import parse from "remark-parse"; | ||
import { unified } from "unified"; | ||
import { visit } from "unist-util-visit"; | ||
|
||
function remarkTokenReplacer(options) { | ||
const replacements = options.replacements || {}; | ||
|
||
const replaceTokens = (node) => { | ||
// test to see if any of the replacement tokens are in the node | ||
const hasToken = Object.keys(replacements).some((token) => | ||
node.value.includes(token) | ||
const replaceTokens = (node, index, parent) => { | ||
// Test to see if any of the replacement tokens are in the node | ||
const hasToken = Object.keys(replacements).some( | ||
(token) => node.value && node.value.includes(token) | ||
); | ||
|
||
if (!hasToken) { | ||
return; | ||
} else { | ||
Object.entries(replacements).forEach(([token, value]) => { | ||
if (!node.value.includes(token)) { | ||
return; | ||
if (!hasToken) return | ||
|
||
Object.entries(replacements).forEach(([token, value]) => { | ||
if (!node.value.includes(token)) { | ||
return; | ||
} | ||
|
||
// If the `token` ends with `_LINK`, then replace this node with a link node | ||
if (token.endsWith("_LINK")) { | ||
// Parse the replacement value, assumed to be markdown link | ||
const parsedMarkdown = unified().use(parse).parse(value); | ||
let replacementLink; | ||
|
||
visit(parsedMarkdown, "link", (node) => { | ||
replacementLink = node; | ||
}); | ||
|
||
// If the entire text node is only the token, replace the entire node | ||
// Else if it is part of a larger text node, replace just the token | ||
if (node.value === token) { | ||
parent.children.splice(index, 1, replacementLink); | ||
} else { | ||
const [before, after] = node.value.split(token); | ||
const beforeNode = { type: "text", value: before }; | ||
const afterNode = { type: "text", value: after }; | ||
parent.children.splice( | ||
index, | ||
1, | ||
beforeNode, | ||
replacementLink, | ||
afterNode | ||
); | ||
} | ||
const oldValue = String(node.value); | ||
} else { | ||
node.value = node.value.replaceAll(new RegExp(token, "gs"), value); | ||
}); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
// Used for replacing variables inside of links such as: | ||
// https://someplace.com/MY_VAR/something | ||
const replaceLink = (node) => { | ||
// Test to see if any of the replacement tokens are in the node | ||
const hasToken = Object.keys(replacements).some( | ||
(token) => node.url && node.url.includes(token) | ||
); | ||
|
||
if (!hasToken) return; | ||
|
||
Object.entries(replacements).forEach(([token, value]) => { | ||
if (!node.url.includes(token)) { | ||
return; | ||
} | ||
|
||
node.url = node.url.replaceAll(new RegExp(token, "gs"), value); | ||
}); | ||
}; | ||
|
||
return (tree) => { | ||
// print the tree to see what it looks like | ||
visit(tree, "text", replaceTokens); | ||
visit(tree, "code", replaceTokens); | ||
visit(tree, "link", replaceLink); | ||
}; | ||
} | ||
|
||
export default remarkTokenReplacer; | ||
export default remarkTokenReplacer; |