Skip to content

Commit

Permalink
pkp/pkp-lib#9421 Pass configAllowedHtml config from server, fix story…
Browse files Browse the repository at this point in the history
…book
  • Loading branch information
jardakotesovec committed Jan 31, 2024
1 parent 13a15d8 commit 92eae25
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ setup((app) => {
app.use(pinia);

// directives
vueApp.directive('pkp-allowed-html', allowedHtmlDirective);
app.directive('pkp-allowed-html', allowedHtmlDirective);

app.mixin(GlobalMixins);

Expand Down
5 changes: 5 additions & 0 deletions public/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
* are not part of the UI Library's responsibilities
*/
window.pkp = {
serverContext: {
configAllowedHtml:
'a[href|target|title],em,strong,cite,code,ul,ol,li[class],dl,dt,dd,b,i,u,img[src|alt],sup,sub,br,p',
apiBaseUrl: 'https://mock/index.php/publicknowledge/api/v1/',
},
/**
* Event bus. This will be a Vue instance but must be registered in main.js
* where Vue can be imported
Expand Down
6 changes: 3 additions & 3 deletions src/composables/useApiUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import {ref, computed} from 'vue';
*/

export function useApiUrl(_path) {
if (typeof pkp === 'undefined' || !pkp?.context?.apiBaseUrl) {
throw new Error('pkp.context.apiBaseUrl is not configured');
if (typeof pkp === 'undefined' || !pkp?.serverContext?.apiBaseUrl) {
throw new Error('pkp.serverContext.apiBaseUrl is not configured');
}

// normalise to be ref even if its not passed as ref
const path = ref(_path);

const apiUrl = computed(() => `${pkp.context.apiBaseUrl}${path.value}`);
const apiUrl = computed(() => `${pkp.serverContext.apiBaseUrl}${path.value}`);

return {apiUrl};
}
7 changes: 5 additions & 2 deletions src/directive/allowedHtml.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import DOMPurify from 'dompurify';

const allowed_html =
'a[href|target|title],em,strong,cite,code,ul,ol,li[class],dl,dt,dd,b,i,u,img[src|alt],sup,sub,br,p';
if (typeof pkp === 'undefined' || !pkp?.serverContext?.configAllowedHtml) {
throw new Error('pkp.serverContext.configAllowedHtml is not configured');
}

const allowed_html = pkp.serverContext.configAllowedHtml;

const ALLOWED_TAGS = [];
const ALLOWED_ATTR = [];
Expand Down

0 comments on commit 92eae25

Please sign in to comment.