Skip to content

Commit

Permalink
Merge pull request #1 from tomaskikutis/custom-blocks-customization
Browse files Browse the repository at this point in the history
custom blocks customization
  • Loading branch information
tomaskikutis authored Jun 18, 2024
2 parents 9220b3b + aa28e15 commit a8095ee
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 38 deletions.
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "client" # Location of package manifests
schedule:
interval: "daily"
- package-ecosystem: "pip" # See documentation for possible values
directory: "server" # Location of package manifests
schedule:
interval: "daily"
37 changes: 0 additions & 37 deletions client/index.js

This file was deleted.

79 changes: 79 additions & 0 deletions client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import {startApp} from 'superdesk-core/scripts/index';

setTimeout(() => {
startApp(
[
{
id: 'annotationsLibrary',
load: () => import('superdesk-core/scripts/extensions/annotationsLibrary'),
},
{
id: 'markForUser',
load: () => import('superdesk-core/scripts/extensions/markForUser'),
},
{
id: 'datetimeField',
load: () => import('superdesk-core/scripts/extensions/datetimeField'),
},
{
id: 'planning-extension',
load: () => import('superdesk-planning/client/planning-extension'),
},
{
id: 'broadcasting',
load: () => import('superdesk-core/scripts/extensions/broadcasting').then((broadcasting) => {
broadcasting.setCustomizations({
getRundownItemDisplayName: (rundown) => rundown.technical_title,
});

return broadcasting;
}),
},
],
{},
{
editor3: {
customBlocks: {
getAdditionalWrapperAttributes: (_vocabulary, html) => {
function getHighestHeadingText(el: HTMLElement): string | null {
const headings: Array<keyof HTMLElementTagNameMap> = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];

for (const tag of headings) {
const result = el.querySelector(tag);

if (result != null) {
return result.textContent;
}
}

return null;
}

const tableCellContentElement: HTMLElement =
new DOMParser().parseFromString(html, 'text/html').body;

const replaceSpecialCharacters = (str) =>
str.normalize('NFD').replace(/[\u0300-\u036f]/g, '') // Remove accents
.replace(/([^\w]+|\s+)/g, '-') // Replace space and other characters by hyphen
.replace(/\-\-+/g, '-') // replace multiple hyphens with one hyphen
.replace(/(^-+|-+$)/g, ''); // remove extra hyphens from beginning or end of the string

const heading: string | null = getHighestHeadingText(tableCellContentElement);

const attributes: Array<{name: string; value: string}> = [
{name: 'class', value: 'custom-block'},
];

if (heading != null) {
attributes.push({name: 'data-custom-block-title', value: replaceSpecialCharacters(heading).toLocaleLowerCase()});
}

return attributes;
},
},
},
},
);
});

export default angular.module('main.superdesk', []);
2 changes: 1 addition & 1 deletion server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,4 @@
# 2: reindex slugline
SCHEMA_VERSION = 2

#CORRECTIONS_WORKFLOW = True
# CORRECTIONS_WORKFLOW = True

0 comments on commit a8095ee

Please sign in to comment.