A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
at lambda-fork/main 63 lines 1.8 kB view raw
1// SiYuan - Refactor your thinking 2// Copyright (c) 2020-present, b3log.org 3// 4// This program is free software: you can redistribute it and/or modify 5// it under the terms of the GNU Affero General Public License as published by 6// the Free Software Foundation, either version 3 of the License, or 7// (at your option) any later version. 8// 9// This program is distributed in the hope that it will be useful, 10// but WITHOUT ANY WARRANTY; without even the implied warranty of 11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12// GNU Affero General Public License for more details. 13// 14// You should have received a copy of the GNU Affero General Public License 15// along with this program. If not, see <https://www.gnu.org/licenses/>. 16 17package model 18 19import ( 20 "strings" 21 22 "github.com/pdfcpu/pdfcpu/pkg/pdfcpu/model" 23) 24 25func PdfListLinks(ctx *model.Context) (assets, others []model.LinkAnnotation, err error) { 26 for pg, annos := range ctx.PageAnnots { 27 for k, v := range annos { 28 if model.AnnLink == k { 29 for _, va := range v.Map { 30 link := va.ContentString() 31 l := va.(model.LinkAnnotation) 32 l.Page = pg 33 if strings.HasPrefix(link, "http://127.0.0.1:") && strings.Contains(link, "/assets/") { 34 assets = append(assets, l) 35 } else { 36 others = append(others, l) 37 } 38 } 39 } 40 } 41 } 42 return 43} 44 45const PdfOutlineScheme = "pdf-outline" 46 47func PdfListToCLinks(ctx *model.Context) (ret []model.LinkAnnotation, err error) { 48 for pg, annos := range ctx.PageAnnots { 49 for k, v := range annos { 50 if model.AnnLink == k { 51 for _, va := range v.Map { 52 link := va.ContentString() 53 if strings.HasPrefix(link, PdfOutlineScheme+"://") { 54 l := va.(model.LinkAnnotation) 55 l.Page = pg 56 ret = append(ret, l) 57 } 58 } 59 } 60 } 61 } 62 return 63}