MOBILE-4176 grades: Keep new lines

main
Noel De Martin 2022-12-05 16:54:42 +01:00
parent 3fa72b3a36
commit 324785f36a
7 changed files with 17 additions and 15 deletions

View File

@ -181,7 +181,7 @@ export class AddonModBBBIndexComponent extends CoreCourseModuleMainActivityCompo
return { return {
type: playbackAnchor?.innerText ?? type: playbackAnchor?.innerText ??
Translate.instant('addon.mod_bigbluebuttonbn.view_recording_format_presentation'), Translate.instant('addon.mod_bigbluebuttonbn.view_recording_format_presentation'),
name: CoreTextUtils.cleanTags(String(recordingData.recording), true), name: CoreTextUtils.cleanTags(String(recordingData.recording), { singleLine: true }),
url: playbackAnchor?.href ?? '', url: playbackAnchor?.href ?? '',
details, details,
expanded: false, expanded: false,

View File

@ -87,7 +87,7 @@ export class AddonModWikiEditPage implements OnInit, OnDestroy, CanLeave {
this.userId = CoreNavigator.getRouteNumberParam('userId'); this.userId = CoreNavigator.getRouteNumberParam('userId');
let pageTitle = CoreNavigator.getRouteParam<string>('pageTitle'); let pageTitle = CoreNavigator.getRouteParam<string>('pageTitle');
pageTitle = pageTitle ? CoreTextUtils.cleanTags(pageTitle.replace(/\+/g, ' '), true) : ''; pageTitle = pageTitle ? CoreTextUtils.cleanTags(pageTitle.replace(/\+/g, ' '), { singleLine: true }) : '';
this.canEditTitle = !pageTitle; this.canEditTitle = !pageTitle;
this.title = pageTitle ? this.title = pageTitle ?

View File

@ -62,7 +62,7 @@ export class CoreMarkRequiredComponent implements OnInit, AfterViewInit {
if (this.coreMarkRequired) { if (this.coreMarkRequired) {
// Add the "required" to the aria-label. // Add the "required" to the aria-label.
const ariaLabel = this.element.getAttribute('aria-label') || const ariaLabel = this.element.getAttribute('aria-label') ||
CoreTextUtils.cleanTags(this.element.innerHTML, true); CoreTextUtils.cleanTags(this.element.innerHTML, { singleLine: true });
if (ariaLabel) { if (ariaLabel) {
this.element.setAttribute('aria-label', ariaLabel + ' ' + this.requiredLabel); this.element.setAttribute('aria-label', ariaLabel + ' ' + this.requiredLabel);
} }

View File

@ -222,7 +222,7 @@ export class CoreFilterProvider {
} }
if (options.clean) { if (options.clean) {
text = CoreTextUtils.cleanTags(text, options.singleLine); text = CoreTextUtils.cleanTags(text, { singleLine: options.singleLine });
} }
if (options.shortenLength && options.shortenLength > 0) { if (options.shortenLength && options.shortenLength > 0) {

View File

@ -137,15 +137,13 @@ export class CoreGradesHelperProvider {
row.rowclass += itemNameColumn.class.indexOf('hidden') >= 0 ? ' hidden' : ''; row.rowclass += itemNameColumn.class.indexOf('hidden') >= 0 ? ' hidden' : '';
row.rowclass += itemNameColumn.class.indexOf('dimmed_text') >= 0 ? ' dimmed_text' : ''; row.rowclass += itemNameColumn.class.indexOf('dimmed_text') >= 0 ? ' dimmed_text' : '';
if (useLegacyLayout) { if (!useLegacyLayout && !CoreAppProvider.isAutomated()) {
content = content.replace(/<\/span>/gi, '\n'); // Activity name is only included in the webservice response from the latest version when behat is not running.
content = CoreTextUtils.cleanTags(content); content = content.replace(/<span[^>]+>.+?<\/span>/i, '');
} else {
// The activity type won't be included in the webservice response if behat is running.
content = CoreAppProvider.isAutomated() ? content : content.replace(/<span[^>]+>.+?<\/span>/i, '');
content = CoreTextUtils.cleanTags(content, true);
} }
content = content.replace(/<\/span>/gi, '\n');
content = CoreTextUtils.cleanTags(content, { trim: true });
name = 'gradeitem'; name = 'gradeitem';
} else if (name === 'grade') { } else if (name === 'grade') {
// Add the pass/fail class if present. // Add the pass/fail class if present.

View File

@ -415,7 +415,7 @@ export class CoreQuestionHelperProvider {
// Check anchor is valid. // Check anchor is valid.
if (anchor.href && content) { if (anchor.href && content) {
content = CoreTextUtils.cleanTags(content, true).trim(); content = CoreTextUtils.cleanTags(content, { singleLine: true, trim: true });
attachments.push({ attachments.push({
filename: content, filename: content,
fileurl: anchor.href, fileurl: anchor.href,

View File

@ -277,10 +277,12 @@ export class CoreTextUtilsProvider {
* Clean HTML tags. * Clean HTML tags.
* *
* @param text The text to be cleaned. * @param text The text to be cleaned.
* @param singleLine True if new lines should be removed (all the text in a single line). * @param options Processing options.
* @param options.singleLine True if new lines should be removed (all the text in a single line).
* @param options.trim True if text should be trimmed.
* @returns Clean text. * @returns Clean text.
*/ */
cleanTags(text: string | undefined, singleLine?: boolean): string { cleanTags(text: string | undefined, options: { singleLine?: boolean; trim?: boolean } = {}): string {
if (!text) { if (!text) {
return ''; return '';
} }
@ -289,8 +291,10 @@ export class CoreTextUtilsProvider {
text = text.replace(/(<([^>]+)>)/ig, ''); text = text.replace(/(<([^>]+)>)/ig, '');
// Then, we rely on the browser. We need to wrap the text to be sure is HTML. // Then, we rely on the browser. We need to wrap the text to be sure is HTML.
text = this.convertToElement(text).textContent || ''; text = this.convertToElement(text).textContent || '';
// Trim text
text = options.trim ? text.trim() : text;
// Recover or remove new lines. // Recover or remove new lines.
text = this.replaceNewLines(text, singleLine ? ' ' : '<br>'); text = this.replaceNewLines(text, options.singleLine ? ' ' : '<br>');
return text; return text;
} }