From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id qEH+HKtC/WRj+QAA9RJhRA:P1 (envelope-from ) for ; Sun, 10 Sep 2023 06:14:35 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id qEH+HKtC/WRj+QAA9RJhRA (envelope-from ) for ; Sun, 10 Sep 2023 06:14:35 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 129AF58469 for ; Sun, 10 Sep 2023 06:14:34 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=thompsonclan-org.20230601.gappssmtp.com header.s=20230601 header.b=OzqgeaZV; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1694319275; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=8E1qFBPMZJD+rVL2hROlUGISrcl2ESb2ylPNqYd8iyE=; b=XW6YIM/c1Ei+SJZUfj+GK7XcZ5ZpOHYPavJ5zH43Cke59eLMHuo4YOJ1pWn/aB7bS1xGwv UPxcSEmH51LHPiGAVCdi9DV1559USNjMQNFAxTVd3hH720YaiQ9KzTFAo5nLbhck6LdvTD F5D2cX4lahYxPzctterbAjO0a5cUatPXJ3+4226UR6N0P4pEWj9Y6iMBkl5qDvH2a7FcW7 zinj10Jr1sAe8/8CBx8t29rrFlrI7IMziJusucV5D53Q01nI+8SmE0hgEMqlNwWWNaaafi JERD63tFrIfb9Fc/xwL8DPyTuPJuYxEqTE9oKxtt7dyl3PAk1VdEiulHUxxFiA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=thompsonclan-org.20230601.gappssmtp.com header.s=20230601 header.b=OzqgeaZV; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Seal: i=1; s=key1; d=yhetil.org; t=1694319275; a=rsa-sha256; cv=none; b=hrB9U4Xj/zXdsT0+H85sRc3h0MnUbW1wv7ImhdWO2Zo2jaZPgA/H0Z33jfQ+RncHMeH6Lg yjcDsjY1D7kxHiXv5MWwqfaUnR9QktXvXUVkcGM3yY4uT6h8Pq+/4hb3cayV8t52oRMFEQ Mucy7az9CfKvdo5ug1nwNbCzOnTJ7podTxQWpmygja62sw/+kmqNWa77xAlV5aQ4w/MGej 0HRUtKJMXIN0rn13DxIPDCSzZzgIEEX+/QGYesGUL+Ylw/ZB2yBQbLwCFUglZzYb4CrKzO y3fgrvNYyJFeMLS5lsLokQ6WGHmODaA1mfWbYBiJhdp3j9vf5g9CCF/aX2LImA== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qfBpb-0005GN-W7; Sun, 10 Sep 2023 00:13:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qfBpa-0005Fw-LG for emacs-orgmode@gnu.org; Sun, 10 Sep 2023 00:13:54 -0400 Received: from mail-qt1-x82d.google.com ([2607:f8b0:4864:20::82d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qfBpX-00071r-KR for emacs-orgmode@gnu.org; Sun, 10 Sep 2023 00:13:54 -0400 Received: by mail-qt1-x82d.google.com with SMTP id d75a77b69052e-41206fd9717so22704911cf.3 for ; Sat, 09 Sep 2023 21:13:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thompsonclan-org.20230601.gappssmtp.com; s=20230601; t=1694319230; x=1694924030; darn=gnu.org; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=8E1qFBPMZJD+rVL2hROlUGISrcl2ESb2ylPNqYd8iyE=; b=OzqgeaZVSM+bCtfgvvXQSEOLGTl0h79p/E3YgnAfZBT4+625trtAObIHbJQjTq+yQY DAGOZPUM5efA2NP3AnulxuGwxWgq8W0YeyNOHMRpNkCRaJsktAvQErjEypjfvknJ1A20 LS+nN7MrXuTW/aMKdUjZh3TLMSNNRlR6zDiIiOvGhK/ArGIssTIo0It8sLTIH1rvDI2M 4SMqqIvkdptYv7x6Pij4f+QHpgf+AdhlYy3oEjLce9jdYcMNu+YmIEvNAIl4VYKX4zWE FQ3YGBvBpsVVs3ypkzI3Pfki+NgxOuZFvFB1LULd8+Q4AM/gHPJCUj33WuhNciV56znB eZ0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694319230; x=1694924030; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=8E1qFBPMZJD+rVL2hROlUGISrcl2ESb2ylPNqYd8iyE=; b=dFQf2Lm4LmR2so1PkNcfg1TGg+FTlySgLCl1PojBU1c1hSUR8cRNRaArXa+Q2EB4Sj UT6HNMdgwbInFb5nZyd9Mk7nSDmGC/+2qhs6U5WAKEC4zSWiFhFG51c+jaTH1I3WUua3 mVgUetd+HgcC1szEofQkkYW3635r7dt7cVUQF9qQLXPNGJpXByL1PcyfUb0WzrfMIUKs oHdOBYa2Hpmky2qxJI5gxQlHl95UJviPF2Ft3id5+6epku/dIvsQ+GJJiYnuRPoJBcYI PYTE5AMEq+gnik4AGHzXEpAthXIDVoQOqo6yyIWaWNnMIzCsOGgRKeNoZLCmljGg3+b4 OqhA== X-Gm-Message-State: AOJu0YxrlfwfJhMIj4ZkPz4go3scPo0PrB7kMD7I8ungwojy2UbQCuje qcCJmzEHAsGpePZjnYAjjovLvHvgbSDy+IDA5dJ1iQ== X-Google-Smtp-Source: AGHT+IG3EXtKm+s5h/hy65/SyjJb2/DOSU+bcY+WGVoPsz/MuHLmQxGV4dgc1JRtlo6IXFMr4JxT9g== X-Received: by 2002:a05:622a:180f:b0:405:5679:463a with SMTP id t15-20020a05622a180f00b004055679463amr8054621qtc.0.1694319229813; Sat, 09 Sep 2023 21:13:49 -0700 (PDT) Received: from [192.168.10.202] (pool-108-41-191-93.nycmny.fios.verizon.net. [108.41.191.93]) by smtp.gmail.com with ESMTPSA id i21-20020a05620a145500b0076cdc3b5beasm1663422qkl.86.2023.09.09.21.13.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 09 Sep 2023 21:13:49 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------6978EZCjeypeuq79PPLmZDeE" Message-ID: Date: Sun, 10 Sep 2023 00:13:47 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Feature request: Allow export to convert broken links to plain text To: "Berry, Charles" Cc: Org-Mode List References: <6DD23F17-400A-468E-B637-5E2A9C7995DD@ucsd.edu> <6C73C452-CA9E-45A0-8529-61BDCDA0B580@ucsd.edu> Content-Language: en-US From: "Ryan C. Thompson" In-Reply-To: <6C73C452-CA9E-45A0-8529-61BDCDA0B580@ucsd.edu> Received-SPF: none client-ip=2607:f8b0:4864:20::82d; envelope-from=rct@thompsonclan.org; helo=mail-qt1-x82d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Queue-Id: 129AF58469 X-Migadu-Scanner: mx1.migadu.com X-Migadu-Spam-Score: -3.92 X-Spam-Score: -3.92 X-TUID: 5c9+yS3CWuiA This is a multi-part message in MIME format. --------------6978EZCjeypeuq79PPLmZDeE Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 1/13/19 5:34 PM, Berry, Charles wrote: > Looks like your original idea to revise `org-export-data' might be best. > > IIUC, you need to add the link text to the SIGNAL-DATA in each of the places where `org-export-resolve-*-link' functions call `signal', then modify `org-export-data' to ignore the addition for `mark' and add it back for your new `mark-with-text' option. > > HTH, > > Chuck Years later, I became annoyed enough by this to attempt to fix it again. Unfortunately, I looked into changing all the functions that signal org-link-broken, and not all of them can be modified in the way you described, at least not easily. Instead, I came up with a fairly clean alternative solution: define a new link type "maybe" using org-link-set-parameters with an :export function that pulls out the real link transcoder from the backend and calls it, but then implements my desired behavior if that transcoder throws an error. This allows you to prefix any link's path with "maybe:" to have it magically become plain text if it can't be resolved during export. Here's the implementation: (org-link-set-parameters  "maybe"  :follow  (lambda (path prefix)    (condition-case err        (org-link-open-from-string (format "[[%s]]" path))      (error (message "Failed to open maybe link %S" path))))  ;; This must be a lambda so it is self-contained  :export  (lambda (path desc backend &optional info)    (when (symbolp backend)      (setq backend (org-export-get-backend backend)))    ;; Generate the non-maybe version of the link, and call the    ;; backend's appropriate transcoder on it, but catch any error    ;; thrown and just replace the link with its text instead.    (let* ((real-link            (with-temp-buffer          (save-excursion (insert "[[" path "][" desc "]]"))          (org-element-link-parser)))           (real-link-transcoder (cdr (assoc 'link (org-export-get-all-transcoders backend)))))      (condition-case err          (funcall real-link-transcoder real-link desc info)        (error         (message "Skipping error during maybe link transcoding: %S" err)         (or desc path)))))) Using the above code, the following org file can be successfully exported to HTML, with the broken/invalid links converted to just plain text. * First heading :PROPERTIES: :CUSTOM_ID: heading1 :END: - [[maybe:maybe:maybe:https://google.com][Maybe google]] - [[maybe:#heading1][Link to first heading]] - [[maybe:#heading2][Link to second heading]] - [[maybe:#heading3][Link to third(?) heading]] - [[maybe:blarg:notalink][This is an invalid link]] * Second heading :PROPERTIES: :CUSTOM_ID: heading2 :END: So, this isn't an ideal solution, since it requires me to prefix any potential offending links with "maybe:". But it's good enough for me. Regards, Ryan --------------6978EZCjeypeuq79PPLmZDeE Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


On 1/13/19 5:34 PM, Berry, Charles wrote:
Looks like your original idea to revise `org-export-data' might be best. 

IIUC, you need to add the link text to the SIGNAL-DATA in each of the places where `org-export-resolve-*-link' functions call `signal', then modify `org-export-data' to ignore the addition for `mark' and add it back for your new `mark-with-text' option.

HTH,

Chuck

Years later, I became annoyed enough by this to attempt to fix it again. Unfortunately, I looked into changing all the functions that signal org-link-broken, and not all of them can be modified in the way you described, at least not easily. Instead, I came up with a fairly clean alternative solution: define a new link type "maybe" using org-link-set-parameters with an :export function that pulls out the real link transcoder from the backend and calls it, but then implements my desired behavior if that transcoder throws an error. This allows you to prefix any link's path with "maybe:" to have it magically become plain text if it can't be resolved during export. Here's the implementation:


(org-link-set-parameters
 "maybe"
 :follow
 (lambda (path prefix)
   (condition-case err
       (org-link-open-from-string (format "[[%s]]" path))
     (error (message "Failed to open maybe link %S" path))))
 ;; This must be a lambda so it is self-contained
 :export
 (lambda (path desc backend &optional info)
   (when (symbolp backend)
     (setq backend (org-export-get-backend backend)))
   ;; Generate the non-maybe version of the link, and call the
   ;; backend's appropriate transcoder on it, but catch any error
   ;; thrown and just replace the link with its text instead.
   (let* ((real-link
           (with-temp-buffer
         (save-excursion (insert "[[" path "][" desc "]]"))
         (org-element-link-parser)))
          (real-link-transcoder (cdr (assoc 'link (org-export-get-all-transcoders backend)))))
     (condition-case err
         (funcall real-link-transcoder real-link desc info)
       (error
        (message "Skipping error during maybe link transcoding: %S" err)
        (or desc path))))))


Using the above code, the following org file can be successfully exported to HTML, with the broken/invalid links converted to just plain text.


* First heading
:PROPERTIES:
:CUSTOM_ID: heading1
:END:
- [[maybe:maybe:maybe:https://google.com][Maybe google]]
- [[maybe:#heading1][Link to first heading]]
- [[maybe:#heading2][Link to second heading]]
- [[maybe:#heading3][Link to third(?) heading]]
- [[maybe:blarg:notalink][This is an invalid link]]
* Second heading
:PROPERTIES:
:CUSTOM_ID: heading2
:END:


So, this isn't an ideal solution, since it requires me to prefix any potential offending links with "maybe:". But it's good enough for me.


Regards,

Ryan

--------------6978EZCjeypeuq79PPLmZDeE--