一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
56 行
1.7 KiB
TypeScript
56 行
1.7 KiB
TypeScript
import { escapeHtml } from '../../string-utils';
|
|
import { ColumnName, ListRendererItemValueTemplates, NoteListColumns, RenderNoteView } from '../plugins/api/noteListType';
|
|
import * as Mustache from 'mustache';
|
|
import { objectValueFromPath } from '@joplin/utils/object';
|
|
|
|
interface Cell {
|
|
name: ColumnName;
|
|
styleHtml: string;
|
|
value: unknown;
|
|
contentHtml: ()=> string;
|
|
}
|
|
|
|
const valueToString = (value: unknown) => {
|
|
if (value === undefined || value === null) return '';
|
|
return String(value);
|
|
};
|
|
|
|
export default (columns: NoteListColumns, itemTemplate: string, itemValueTemplates: ListRendererItemValueTemplates, view: RenderNoteView) => {
|
|
// `note.title` is special and has already been rendered to HTML at this point, so we need
|
|
// to ensure the string is not going to be escaped.
|
|
itemTemplate = itemTemplate.replace(/\{\{note.title\}\}/g, '{{{note.title}}}');
|
|
if (!columns || !columns.length) return Mustache.render(itemTemplate, view);
|
|
|
|
const cells: Cell[] = [];
|
|
|
|
for (const column of columns) {
|
|
const styleHtml: string[] = [];
|
|
|
|
if (column.width) {
|
|
styleHtml.push(`width: ${column.width}px`);
|
|
} else {
|
|
styleHtml.push('flex: 1');
|
|
}
|
|
|
|
cells.push({
|
|
name: column.name,
|
|
styleHtml: styleHtml.join('; '),
|
|
value: objectValueFromPath(view, column.name) || '',
|
|
contentHtml: function() {
|
|
const name = this.name as ColumnName;
|
|
if (itemValueTemplates[name]) {
|
|
return Mustache.render(itemValueTemplates[name], view);
|
|
}
|
|
return ['note.titleHtml', 'note.title'].includes(name) ? String(this.value) : escapeHtml(valueToString(this.value));
|
|
},
|
|
});
|
|
}
|
|
|
|
const finalView = {
|
|
cells,
|
|
...view,
|
|
};
|
|
|
|
return Mustache.render(itemTemplate, finalView);
|
|
};
|