Quantcast

how to include a snippet of html?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

how to include a snippet of html?

RichardH

    Q. How to make an html which
      includes:: a snippet of html + javascript?

    I'm trying to make an html file which includes
    a snippet of html
    
    The snippet has an obfuscated bit of javascript  [1]
    that renders in html as
        "you can write to me here" with my email

    For txt2tags, the following works out-of-the-box:-
        %!include(html): ''./email_obfuscator_script.html''

    For asciidoctor I've tried, as per my understanding of
    the manual this:-

        [source,html]
        ----
        include::./email_obfuscator_script.html[]
        ----

    and this:-
        [source,xhtml]
        ----
        include::./email_obfuscator_script.html[]
        ----

    and this:-
        [format="html"]
        include::./email_obfuscator_script.html[]

    They all import the file, but render it as code,
    not as html
    
    Your help gratefully received
    Richard H

[1] With thanks to http://www.jottings.com/obfuscator/
--

-- 
    
    ===============================================
    82 AVENUE WALCKIERS  B-1160 AUDERGHEM  BELGIQUE
    tel   +32 (0)2 660 52 23
    email  [hidden email]
    ===============================================

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to include a snippet of html?

mojavelinux
Administrator
You'll want to use a passthrough block.


I do need to mention, however, that a passthough block should only be used as a last resort. You should think of it as a brute force approach that you sometimes need to use in the essence of time.

The correct way to add supplemental HTML to a page is either to use a block or block macro extension or docinfo. You can see an example of a custom block macro to insert HTML in the gist block macro in the extensions lab. See https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/lib/gist-block-macro/extension.rb

Cheers,

-Dan

On Tue, Feb 21, 2017 at 9:57 AM, RichardH [via Asciidoctor :: Discussion] <[hidden email]> wrote:

    Q. How to make an html which
      includes:: a snippet of html + javascript?

    I'm trying to make an html file which includes
    a snippet of html
    
    The snippet has an obfuscated bit of javascript  [1]
    that renders in html as
        "you can write to me here" with my email

    For txt2tags, the following works out-of-the-box:-
        %!include(html): ''./email_obfuscator_script.html''

    For asciidoctor I've tried, as per my understanding of
    the manual this:-

        [source,html]
        ----
        include::./email_obfuscator_script.html[]
        ----

    and this:-
        [source,xhtml]
        ----
        include::./email_obfuscator_script.html[]
        ----

    and this:-
        [format="html"]
        include::./email_obfuscator_script.html[]

    They all import the file, but render it as code,
    not as html
    
    Your help gratefully received
    Richard H

[1] With thanks to http://www.jottings.com/obfuscator/
--

-- 
    
    ===============================================
    82 AVENUE WALCKIERS  B-1160 AUDERGHEM  BELGIQUE
    tel   <a href="tel:+32%202%20660%2052%2023" value="+3226605223" target="_blank">+32 (0)2 660 52 23
    email  [hidden email]
    ===============================================




If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/how-to-include-a-snippet-of-html-tp5293.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to include a snippet of html?

RichardH
Thank you for quick reply

Kind correspondent off list suggested another brute force approach:
- put a marker «You can write to me here»
in the adoc, process to html,
and run a little Perl script [1] on that html

Works like a charm
Richard H

[1]
...snip...
    #zfile is the email_obfuscator_script.html
    use File::Slurp;
    my $replacement_text = read_file($zfile);
    open INFILE, "<", $infile or croak;
    open OUTFILE,">",$outfile or croak;
    my $done_something = 0;
    while(<INFILE>){
        if(/You can write to me here/){
            print OUTFILE $replacement_text;
            ++$done_something;
        }
        else{
            print OUTFILE;
        }
    }
...snip...

On 02/21/2017 10:29 PM, mojavelinux [via Asciidoctor :: Discussion] wrote:

> You'll want to use a passthrough block.
>
> http://asciidoctor.org/docs/user-manual/#pass-bl
>
> I do need to mention, however, that a passthough block should only be
> used as a last resort. You should think of it as a brute force approach
> that you sometimes need to use in the essence of time.
>
> The correct way to add supplemental HTML to a page is either to use a
> block or block macro extension or docinfo. You can see an example of a
> custom block macro to insert HTML in the gist block macro in the
> extensions lab.
> See
https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/lib/gist-block-macro/extension.rb
>
> Cheers,
>
> -Dan
>

--
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to include a snippet of html?

mojavelinux
Administrator
Richard,

I'm glad you received some other input off list as well.

I'll want to reinforce, especially for others reading, that using a Perl script for something like this is an extremely brute force approach. I, personally, don't condone or recommend that method. We have facilities to handle these use cases in AsciiDoc, and capabilities like passthrough blocks and docinfo are key reasons for choosing AsciiDoc. If you're post processing the HTML, there's a very good chance you overlooked a capability in Asciidoctor. (But, I do understand that sometimes, ugly gets the job done).

Cheers,

-Dan

On Tue, Feb 21, 2017 at 11:59 PM, RichardH [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Thank you for quick reply

Kind correspondent off list suggested another brute force approach:
- put a marker «You can write to me here»
in the adoc, process to html,
and run a little Perl script [1] on that html

Works like a charm
Richard H

[1]
...snip...
    #zfile is the email_obfuscator_script.html
    use File::Slurp;
    my $replacement_text = read_file($zfile);
    open INFILE, "<", $infile or croak;
    open OUTFILE,">",$outfile or croak;
    my $done_something = 0;
    while(<INFILE>){
        if(/You can write to me here/){
            print OUTFILE $replacement_text;
            ++$done_something;
        }
        else{
            print OUTFILE;
        }
    }
...snip...

On 02/21/2017 10:29 PM, mojavelinux [via Asciidoctor :: Discussion] wrote:

> You'll want to use a passthrough block.
>
> http://asciidoctor.org/docs/user-manual/#pass-bl
>
> I do need to mention, however, that a passthough block should only be
> used as a last resort. You should think of it as a brute force approach
> that you sometimes need to use in the essence of time.
>
> The correct way to add supplemental HTML to a page is either to use a
> block or block macro extension or docinfo. You can see an example of a
> custom block macro to insert HTML in the gist block macro in the
> extensions lab.
> See
https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/lib/gist-block-macro/extension.rb
>
> Cheers,
>
> -Dan
>

--



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/how-to-include-a-snippet-of-html-tp5293p5295.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux
Loading...