Nekhelesh closed issue #3: Adding URLs is unnecessarily convoluted at Nekhelesh / PdfPug

Nekhelesh
2019-09-09T03:45:11Z

Problem Statement

While creating the Python Wiki Tutorial, there was a need to embed several URL links within a Paragraph element. The HTML tag for creating a URL is unnecessarily convoluted and reduces the readability of the code.

Here is sample code that illustrates the problem,

intro_para = Paragraph(
'Python is an '
'interpreted, <a href="https://en.wikipedia.org/wiki/High-level_'
'programming_language">high-level, <a href="https://en.wikipedia.org/'
'wiki/General-purpose_programming_language">general-purpose '
'programming '
'language. Created by <a href="https://en.wikipedia.org/wiki/Guido_van_'
"Rossum\">Guido van Rossum and first released in 1991, Python's design "
'philosophy emphasizes <a href="https://en.wikipedia.org/wiki/Code_'
'readability">code readability with its notable use of <a href="https:'
'//en.wikipedia.org/wiki/Off-side_rule">significant whitespace. Its '
"language constructs and object-oriented approach aim to help "
"programmers write clear, logical code for small and large-scale projects.[27]"
)

Proposed Solution

The issue here is the verbosity and the HTML syntax to create a URL. This can be abstracted away using an internal PdfPug function.

def url(string, link):
return f'{string}'

interpreted_lang = url("interpreted", "https://en.wikipedia.org/wiki/High-level_programming_language")