Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Adicionar tags de parágrafo</title>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
- <style>
- textarea {
- width: 100%;
- height: 500px;
- }
- </style>
- </head>
- <body>
- <div class="container my-5">
- <form>
- <textarea id="textarea"></textarea><br>
- <button type="button" class="btn btn-primary mr-2" onclick="addParagraphTags()">Adicionar tags de parágrafo</button>
- <button type="button" class="btn btn-secondary mr-2" onclick="boldSelectedText()">Negrito</button>
- <button type="button" class="btn btn-success mr-2" onclick="copyText()">Copiar para área de transferência</button>
- <button type="button" class="btn btn-info" onclick="addHyperlink()">Hyperlink</button>
- </form>
- </div>
- <script>
- function addParagraphTags() {
- var textarea = document.getElementById("textarea");
- var text = textarea.value;
- var paragraphs = text.split("\n");
- for (var i = 0; i < paragraphs.length; i++) {
- paragraphs[i] = "<p>" + paragraphs[i] + "</p>";
- }
- textarea.value = paragraphs.join("\n");
- }
- function boldSelectedText() {
- var textarea = document.getElementById("textarea");
- var start = textarea.selectionStart;
- var end = textarea.selectionEnd;
- var selectedText = textarea.value.substring(start, end);
- var newText = textarea.value.substring(0, start) + "<b>" + selectedText + "</b>" + textarea.value.substring(end);
- textarea.value = newText;
- }
- function copyText() {
- var textarea = document.getElementById("textarea");
- textarea.select();
- document.execCommand("copy");
- alert("Texto copiado para a área de transferência");
- }
- function addHyperlink() {
- var textarea = document.getElementById("textarea");
- var start = textarea.selectionStart;
- var end = textarea.selectionEnd;
- var selectedText = textarea.value.substring(start, end);
- var url = prompt("Informe a URL");
- var textarea = document.getElementById("textarea");
- var text = textarea.value;
- var start = textarea.selectionStart;
- var end = textarea.selectionEnd;
- var selectedText = text.substring(start, end);
- var newText = text.substring(0, start) + "<a href='" + url + "' target='_blank'>" + selectedText + "</a>" + text.substring(end);
- textarea.value = newText;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement