Skip to content

Commit

Permalink
Expose language loaders to the outside
Browse files Browse the repository at this point in the history
  • Loading branch information
marcodejongh authored and conorhastings committed Oct 31, 2018
1 parent 124c6a6 commit d7b9f22
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/async-syntax-highlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ export default (options) => {
static preload() {
return ReactAsyncHighlighter.loadAstGenerator();
}

static async loadLanguage(language) {
const languageLoader = languageLoaders[language];
if (typeof languageLoader === 'function') {
return languageLoader(ReactAsyncHighlighter.registerLanguage);
} else {
throw `Language ${language} not supported`
}
}

static isRegistered = (language) => {
if(!registerLanguage) {
Expand Down Expand Up @@ -67,25 +76,24 @@ export default (options) => {
if (!ReactAsyncHighlighter.astGeneratorPromise) {
ReactAsyncHighlighter.loadAstGenerator();
}

if(!ReactAsyncHighlighter.astGenerator) {
ReactAsyncHighlighter.astGeneratorPromise.then(() => {
this.forceUpdate();
});
}

if(!ReactAsyncHighlighter.isRegistered(this.props.language) && languageLoaders) {
this.loadLanguage();
}
}

loadLanguage() {
const languageLoader = languageLoaders[this.props.language];

if (typeof languageLoader === 'function') {
languageLoader(ReactAsyncHighlighter.registerLanguage).then(() => {
async loadLanguage() {
try {
ReactAsyncHighlighter.loadLanguage(this.props.language).then(() => {
this.forceUpdate();
});
} catch (error) {
console.log(error);
}
}

Expand Down

0 comments on commit d7b9f22

Please sign in to comment.