Copy code snippet, modify and paste into another Div

0

I am designing an experimental system where when clicking a button it copies what is selected (in this case an excerpt in html) like the one below:

<section>
  <h1> titulo </h1>
  <p>texto desta área</p>
</section>

<button>Modificar código</button>

Next it would make a change in the code inserting the tags that need to be inserted (for my need)

[[bloco]]
    [[repetir]]
    <section>
      <h1> titulo </h1>
      <p>texto desta área</p>
    </section>
    [[/repetir]]
[[/bloco}}

Will I need to use regex? Is there any way to do this just by copying the contents, changing and pasting without needing to use regex?

    
asked by anonymous 18.04.2018 / 12:55

1 answer

0

A simple way to copy code is by using innerHTML but you would need something outside to catch that bit of code, for example:

<div id="copiarConteudo">
 <section>
  <h1> titulo </h1>
  <p>texto desta área</p>
 </section>
</div>

In this case it was enough:

<button onclick="Copia();">Copiar</button>
<script>
  function Copia(){
    var codigo = document.getElementById("copiarConteudo").innerHTML;
  }
</script>
    
18.04.2018 / 13:02