Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2cbaa9342d | ||
|
|
38b0fe2a94 |
No files matched your search
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@@ -13,8 +14,24 @@ import (
|
||||
|
||||
// HTMLToMarkdownAuthoring keeps source HTML when conversion loses structure,
|
||||
// attributes, comments or text. This is not a sanitization boundary.
|
||||
var nestedListGap = regexp.MustCompile(`\n[\t ]*\n([\t ]+(?:[-+*]|[0-9]+\.) )`)
|
||||
|
||||
func authoringMarkdown(source string) (string, error) {
|
||||
md, err := HTMLToMarkdown(source)
|
||||
if err != nil {
|
||||
return md, err
|
||||
}
|
||||
// The converter inserts a loose-list gap before nested lists. Only accept
|
||||
// tightening when the resulting DOM matches; code and real paragraphs stay protected.
|
||||
tight := nestedListGap.ReplaceAllString(md, "\n$1")
|
||||
if tight != md && htmlStructure(source) == htmlStructure(MarkdownToHTML(tight)) {
|
||||
return tight, nil
|
||||
}
|
||||
return md, nil
|
||||
}
|
||||
|
||||
func HTMLToMarkdownAuthoring(source string) (string, error) {
|
||||
converted, err := HTMLToMarkdown(source)
|
||||
converted, err := authoringMarkdown(source)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -30,7 +47,7 @@ func HTMLToMarkdownAuthoring(source string) (string, error) {
|
||||
if strings.TrimSpace(raw) == "" {
|
||||
continue
|
||||
}
|
||||
md, e := HTMLToMarkdown(raw)
|
||||
md, e := authoringMarkdown(raw)
|
||||
if e != nil || htmlStructure(raw) != htmlStructure(MarkdownToHTML(md)) {
|
||||
md = rawHTMLBlock(raw)
|
||||
}
|
||||
@@ -171,6 +188,22 @@ func htmlStructure(source string) string {
|
||||
literal = literal || n.Data == "pre" || n.Data == "code" || n.Data == "script" || n.Data == "style"
|
||||
data := n.Data
|
||||
if n.Type == html.TextNode && !literal {
|
||||
// Formatting whitespace beside a nested block is not an inline word
|
||||
// separator. Keep all whitespace between inline siblings significant.
|
||||
if n.Parent != nil && n.Parent.Data == "li" {
|
||||
isList := func(x *html.Node) bool {
|
||||
return x != nil && x.Type == html.ElementNode && (x.Data == "ul" || x.Data == "ol")
|
||||
}
|
||||
if isList(n.NextSibling) {
|
||||
data = strings.TrimRight(data, " \t\r\n")
|
||||
}
|
||||
if isList(n.PrevSibling) {
|
||||
data = strings.TrimLeft(data, " \t\r\n")
|
||||
}
|
||||
if data == "" {
|
||||
return
|
||||
}
|
||||
}
|
||||
if strings.TrimSpace(data) == "" && n.Parent != nil {
|
||||
switch n.Parent.Data {
|
||||
case "ul", "ol", "table", "thead", "tbody", "tfoot", "tr":
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package grammaratur
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAuthoringNestedLists(t *testing.T) {
|
||||
for _, source := range []string{
|
||||
"<ul><li>Parent<ul><li>Child</li></ul></li></ul>",
|
||||
"<ul>\n<li>Parent\n<ul>\n<li>Child</li>\n</ul>\n</li>\n</ul>",
|
||||
"<ul><li>Parent<ul><li>Child<ul><li>Grandchild</li></ul></li></ul></li><li>Sibling</li></ul>",
|
||||
"<ol><li>Parent<ul><li>Child</li></ul></li></ol>",
|
||||
"<ul><li><strong>Parent</strong><ul><li>Child</li></ul></li></ul>",
|
||||
} {
|
||||
md, err := HTMLToMarkdownAuthoring(source)
|
||||
if htmlStructure(source) != htmlStructure(MarkdownAuthoringHTML(md)) {
|
||||
t.Errorf("list structure changed: %q", md)
|
||||
}
|
||||
if err != nil || strings.Contains(md, "{=html}") {
|
||||
plain, _ := HTMLToMarkdown(source)
|
||||
t.Errorf("source=%q md=%q plain=%q rendered=%q err=%v", source, md, plain, MarkdownToHTML(plain), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthoringNestedListPreservesAttributes(t *testing.T) {
|
||||
source := `<ul><li data-custom="keep">Parent<ul><li>Child</li></ul></li></ul>`
|
||||
md, err := HTMLToMarkdownAuthoring(source)
|
||||
if err != nil || MarkdownAuthoringHTML(md) != source {
|
||||
t.Fatalf("protected list changed: %q %v", md, err)
|
||||
}
|
||||
}
|
||||
@@ -69,12 +69,22 @@ func TestOrganizerDashboardLayoutIsolationAndCAS(t *testing.T) {
|
||||
if err = json.Unmarshal(w.Body.Bytes(), &layout); err != nil || len(layout.Widgets) != 0 {
|
||||
t.Fatal("empty layout reset", layout, err)
|
||||
}
|
||||
for _, invalid := range [][]store.DashboardWidget{{{ID: "iframe", Width: 4, Height: 3}}, {{ID: "tasks", Width: 13, Height: 3, Tab: "inbox"}}, {{ID: "tasks", Width: 4, Height: 3, Tab: "secret"}}, {{ID: "progress", Width: 4, Height: 3}, {ID: "progress", Width: 4, Height: 3}}} {
|
||||
for _, invalid := range [][]store.DashboardWidget{{{ID: "iframe", Width: 4, Height: 3}}} {
|
||||
w = taskRequest(s, token, "PUT", "dashboard", map[string]any{"version": layout.Version, "widgets": invalid}, "")
|
||||
if w.Code != 422 {
|
||||
t.Fatal("invalid accepted", w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
for _, id := range []string{"commands", "tomorrow-schedule", "feeds"} {
|
||||
input := []store.DashboardWidget{{ID: "tasks", Width: 13, Height: 0}, {ID: id, Width: 6, Height: 4, Tab: "obsolete"}, {ID: id, Width: 6, Height: 4}}
|
||||
w = taskRequest(s, token, "PUT", "dashboard", map[string]any{"version": layout.Version, "widgets": input}, "")
|
||||
if w.Code != 200 {
|
||||
t.Fatal("normalizable layout rejected", w.Code, w.Body)
|
||||
}
|
||||
if err = json.Unmarshal(w.Body.Bytes(), &layout); err != nil || len(layout.Widgets) != 2 || layout.Widgets[0].Width != 12 || layout.Widgets[0].Height != 2 || layout.Widgets[0].Tab != "inbox" || layout.Widgets[1].Tab != "" {
|
||||
t.Fatal("normalization", layout, err)
|
||||
}
|
||||
}
|
||||
other, err := s.store.CreatePasswordAccount(domain, "dashboardother", "long test password", "Other", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Vendored
+1
-1
@@ -27,7 +27,7 @@
|
||||
d.querySelector('.feed-row').click();await wait(()=>d.querySelector('#feed-reader .feed-body'));
|
||||
d.querySelector('#feed-reader .feed-actions button:last-child').click();await wait(()=>d.querySelector('#feed-reader form'));
|
||||
assert(!['rgba(0, 0, 0, 0)','transparent'].includes(w.getComputedStyle(d.querySelector('.feed-capture')).backgroundColor),'Capture dialog background transparent');
|
||||
const form=d.querySelector('#feed-reader form'),inputs=form.querySelectorAll('input');assert(inputs[2].value==='/notes/{YYYY}/{MM}/{DD}/{Subject}','Wiki default not filled');assert(form.closest('dialog').open&&d.querySelector('#feed-reader .feed-body'),'Capture replaced article');assert(form.querySelector('a[href="/-/sys/config?panel=organizer"]'),'Default settings link missing');await wait(()=>form.querySelector('output').textContent.includes('/rss-'));assert(!form.querySelector('output').textContent.includes('{'),'Template not expanded');inputs[2].value='/notes/feed-ui';inputs[2].dispatchEvent(new w.Event('input'));await wait(()=>form.querySelector('output').textContent.startsWith('/notes/feed-ui/rss-'));inputs[5].checked=true;form.requestSubmit();await wait(()=>d.querySelector('#feed-reader a[href^="/v/uuid:"]'));d.querySelector('.feed-capture button').click();await wait(()=>!d.querySelector('.feed-capture'));assert(d.querySelector('#feed-reader .feed-body'),'Closing capture lost article');
|
||||
const form=d.querySelector('#feed-reader form'),inputs=form.querySelectorAll('input');assert(inputs[2].value==='/notes/{YYYY}/{MM}/{DD}/{Subject}','Wiki default not filled');assert(form.closest('dialog').open&&d.querySelector('#feed-reader .feed-body'),'Capture replaced article');assert(form.querySelector('a[href="/-/sys/config?panel=organizer"]'),'Default settings link missing');await wait(()=>form.querySelector('output').textContent.includes('/rss-'));assert(!form.querySelector('output').textContent.includes('{'),'Template not expanded');inputs[2].value='/notes/feed-ui';inputs[2].dispatchEvent(new w.Event('input'));await wait(()=>form.querySelector('output').textContent.startsWith('/notes/feed-ui/rss-'));inputs[5].checked=true;form.requestSubmit();await wait(()=>d.querySelector('#feed-reader a[href^="/o/uuid:"]'));d.querySelector('.feed-capture button').click();await wait(()=>!d.querySelector('.feed-capture'));assert(d.querySelector('#feed-reader .feed-body'),'Closing capture lost article');
|
||||
const search=d.querySelector('#feed-toolbar input');search.value='';search.dispatchEvent(new w.Event('input',{bubbles:true}));await wait(()=>d.querySelectorAll('.feed-row').length===100);d.querySelector('.feed-row').click();await wait(()=>d.querySelector('#feed-reader .feed-body'));
|
||||
assert(d.documentElement.scrollWidth<=w.innerWidth,'Reader overflow');
|
||||
d.getElementById('feed-opml').click();await wait(()=>d.getElementById('feed-opml-file'));
|
||||
|
||||
@@ -53,6 +53,33 @@ type DashboardLayout struct {
|
||||
Widgets []DashboardWidget `json:"widgets"`
|
||||
}
|
||||
|
||||
func normalizeDashboard(items []DashboardWidget) ([]DashboardWidget, error) {
|
||||
if len(items) > 100 {
|
||||
return nil, ErrTaskInvalid
|
||||
}
|
||||
out := make([]DashboardWidget, 0, len(items))
|
||||
seen := map[string]bool{}
|
||||
for _, item := range items {
|
||||
if seen[item.ID] {
|
||||
continue
|
||||
}
|
||||
seen[item.ID] = true
|
||||
item.Width = max(3, min(12, item.Width))
|
||||
item.Height = max(2, min(10, item.Height))
|
||||
if item.ID == "tasks" {
|
||||
switch item.Tab {
|
||||
case "inbox", "backlog", "someday", "review", "all", "done":
|
||||
default:
|
||||
item.Tab = "inbox"
|
||||
}
|
||||
} else {
|
||||
item.Tab = ""
|
||||
}
|
||||
out = append(out, item)
|
||||
}
|
||||
return out, ValidateDashboard(out)
|
||||
}
|
||||
|
||||
func (s *Store) Dashboard(ctx context.Context, domain, actor string) (DashboardLayout, error) {
|
||||
p := DashboardLayout{Widgets: DefaultDashboard()}
|
||||
if err := taskActor(ctx, s.DB, domain, actor, false); err != nil {
|
||||
@@ -79,9 +106,11 @@ func (s *Store) SaveDashboard(ctx context.Context, domain, actor string, version
|
||||
if version < 0 {
|
||||
return p, ErrTaskInvalid
|
||||
}
|
||||
if err := ValidateDashboard(widgets); err != nil {
|
||||
normalized, err := normalizeDashboard(widgets)
|
||||
if err != nil {
|
||||
return p, err
|
||||
}
|
||||
widgets = normalized
|
||||
tx, err := s.DB.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return p, err
|
||||
|
||||
+1
-1
@@ -273,7 +273,7 @@
|
||||
form.onsubmit=async event=>{event.preventDefault();if(busy||resolved===null||!form.reportValidity())return;const body='Source: '+item.url+'\nFeed: '+item.feed+'\n\n'+notes.value+(copy.checked?'\n\n'+item.body:'');const spec={title:title.value,notes:notes.value,prefix:resolved,body,task:task.checked};const fingerprint=JSON.stringify(spec);if(!pending||pending.fingerprint!==fingerprint)pending={fingerprint,request_id:requestID};busy=true;save.disabled=true;
|
||||
try{let data;if(task.checked){const input={request_id:pending.request_id,title:title.value,notes:(notes.value+'\nSource: '+item.url).trim()};if(spec.prefix){input.wiki_prefix=spec.prefix;input.wiki_body=body;}const res=await fetch('/_/api/v1/extension/organizer.tasks/capture',{method:'POST',credentials:'same-origin',headers:{'Content-Type':'application/json'},body:JSON.stringify(input)});data=await res.json().catch(()=>({}));if(!res.ok||res.redirected)throw Error(t('Capture failed: ','作成に失敗: ')+(data.error||res.status));}
|
||||
else data=await post('note',{request_id:pending.request_id,source:item.source,id:item.id,path:spec.prefix.replace(/\/$/,'')+'/rss-'+pending.request_id,title:title.value,body,confirm_publication:confirm.checked});
|
||||
dialog.replaceChildren(el('h2',t('Created','作成しました')));if(data.item){const a=el('a',t('Open task','タスクを開く'));a.href='/v/plan/task/'+encodeURIComponent(data.item.uuid);dialog.append(a);}const page=data.page_uuid||data.item?.page_uuid;if(page){const a=el('a',t('Open Wiki','Wikiを開く'));a.href='/v/uuid:'+encodeURIComponent(page);dialog.append(el('p'),a);}const done=button(t('Close','閉じる'),'',close);dialog.append(el('p'),done);done.focus();
|
||||
dialog.replaceChildren(el('h2',t('Created','作成しました')));if(data.item){const a=el('a',t('Open task','タスクを開く'));a.href='/v/plan/task/'+encodeURIComponent(data.item.uuid);dialog.append(a);}const page=data.page_uuid||data.item?.page_uuid;if(page){const a=el('a',t('Open Wiki','Wikiを開く'));a.href='/o/uuid:'+encodeURIComponent(page);dialog.append(el('p'),a);}const done=button(t('Close','閉じる'),'',close);dialog.append(el('p'),done);done.focus();
|
||||
}catch(e){notice.textContent=e.message;}finally{busy=false;save.disabled=resolved===null;}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
}
|
||||
const save=button(t('Save layout','配置を保存'),t('Save layout','配置を保存'),async()=>{
|
||||
if(saving||!loaded)return;saving=true;updateControls();
|
||||
try{const data=await request(api+'dashboard',{method:'PUT',signal:AbortSignal.timeout(15000),body:JSON.stringify({version,widgets})});version=data.version;dirty=false;status.textContent=t('Layout saved','配置を保存しました');}
|
||||
try{const data=await request(api+'dashboard',{method:'PUT',signal:AbortSignal.timeout(15000),body:JSON.stringify({version,widgets:widgets.map(({id,width,height,tab})=>({id,width,height,...(id==='tasks'?{tab:tab||'inbox'}:{})}))})});version=data.version;widgets=data.widgets;dirty=false;render();status.textContent=t('Layout saved','配置を保存しました');}
|
||||
catch(e){status.textContent=e.message;}finally{saving=false;updateControls();}
|
||||
});
|
||||
const edit=button('⚙',t('Arrange widgets','ウィジェットを配置'),()=>{editing=!editing;root.classList.toggle('is-arranging',editing);edit.setAttribute('aria-pressed',String(editing));});edit.setAttribute('aria-pressed','false');
|
||||
@@ -122,7 +122,7 @@
|
||||
for(const task of data.items){const row=el('li');row.dataset.task=task.uuid;
|
||||
const title=link(task.title,'/v/plan/task/'+encodeURIComponent(task.uuid));title.title=task.title;window.PagesTaskPresentation?.render(title,task.title,false);
|
||||
row.append(el('span',task.status==='done'?'✓':task.status==='cancelled'?'−':task.status==='doing'?'◐':'○'),title);
|
||||
if(task.page_uuid){const note=link('▣','/v/uuid:'+encodeURIComponent(task.page_uuid));note.title=note.ariaLabel=t('Open linked Wiki page','関連Wikiページを開く');note.className='dashboard-note';row.append(note);}if(task.due_on)row.append(el('time',task.due_on));ul.append(row);
|
||||
if(task.page_uuid){const note=link('▣','/o/uuid:'+encodeURIComponent(task.page_uuid));note.title=note.ariaLabel=t('Open linked Wiki page','関連Wikiページを開く');note.className='dashboard-note';row.append(note);}if(task.due_on)row.append(el('time',task.due_on));ul.append(row);
|
||||
}
|
||||
list.append(ul);if(!data.items.length&&!append)list.append(el('p',t('No matching tasks.','該当するタスクはありません。')));
|
||||
if(data.next){const more=button(t('Load more','続きを表示'),t('Load more','続きを表示'),()=>{more.disabled=true;tasks(tab,true,data.next).finally(()=>{more.disabled=false;});});more.dataset.more='true';panel.append(more);}
|
||||
|
||||
@@ -6,4 +6,4 @@
|
||||
<main id="feeds-app" data-timezone="{{ .FeedTimezone }}" data-writable="{{ .FeedWritable }}" data-tasks="{{ .TasksEnabled }}" data-wiki-prefix="{{ .FeedWikiPrefix }}" data-share-x="{{ .FeedShareX }}" data-link-mode="{{ .FeedLinkMode }}">
|
||||
<div id="feed-toolbar"></div><p id="feed-status" role="status" aria-live="polite"></p>
|
||||
<div class="feed-layout"><aside id="feed-sources" aria-label="{{ T "feeds.title" }}"></aside><section class="feed-index"><div id="feed-columns" aria-hidden="true"></div><div id="feed-rows" tabindex="0" role="listbox" aria-label="{{ T "feeds.title" }}"></div><button type="button" id="feed-more" hidden>↓</button></section><article id="feed-reader" tabindex="0"></article></div>
|
||||
</main><script src="/static/js/feeds.js?v=11" defer></script></body></html>{{ end }}
|
||||
</main><script src="/static/js/feeds.js?v=12" defer></script></body></html>{{ end }}
|
||||
@@ -4,4 +4,4 @@
|
||||
{{ template "organizer-nav" . }}
|
||||
<main id="organizer-dashboard" data-writable="{{ .TaskWritable }}" data-calendar="{{ .CalendarEnabled }}" data-today="{{ .Today }}" data-timezone="{{ .Timezone }}">
|
||||
<header class="dashboard-toolbar"><div><h1>{{ T "organizer.dashboard" }}</h1><small>{{ .Today }} · {{ .Timezone }}</small></div><div id="dashboard-controls"></div></header><p id="dashboard-status" role="status" aria-live="polite"></p><div id="dashboard-grid"></div>
|
||||
</main><script src="/static/js/task-presentation.js?v=1" defer></script><script src="/static/js/dashboard-commands.js?v=1" defer></script><script src="/static/js/organizer-dashboard.js?v=3" defer></script><script src="/static/js/task-productivity.js?v=8" defer></script></body></html>{{ end }}
|
||||
</main><script src="/static/js/task-presentation.js?v=1" defer></script><script src="/static/js/dashboard-commands.js?v=1" defer></script><script src="/static/js/organizer-dashboard.js?v=5" defer></script><script src="/static/js/task-productivity.js?v=8" defer></script></body></html>{{ end }}
|
||||
Reference in new issue
Block a user