SnappySnippetI finally found some time to create this tool. You can install SnappySnippet from Github. It allows easy HTML+CSS extraction from the specified (last inspected) DOM node. Additionally, you can send your code straight to CodePen or JSFiddle. Enjoy! Show
Other features
CodeSnappySnippet is open source, and you can find the code on GitHub. ImplementationSince I've learned quite a lot while making this, I've decided to share some of the problems I've experienced and my solutions to them, maybe someone will find it interesting. First attempt - getMatchedCSSRules()At first I've tried retrieving the original CSS rules (coming from CSS files on the website). Quite amazingly,
this is very simple thanks to Second attempt - getComputedStyle()Then, I've started from something that @CollectiveCognition suggested -
Problem 1 - separating CSS from HTMLThe solution here wasn't very beautiful but quite straightforward. I've assigned IDs to all nodes in the selected subtree and used that ID to create appropriate CSS rules. Problem 2 - removing properties with default valuesAssigning IDs to the nodes worked out nicely, however I found out that each of my CSS rules has
~300 properties making the whole CSS unreadable. Problem 3 - keeping only shorthand propertiesNext thing I have spotted was that properties having shorthand equivalent were unnecessarily printed out (e.g. there was Problem 4 - removing prefixed propertiesThe number of properties in each rule was significantly lower after the previous operation, but I've found that I sill had a lot of Problem 5 - combining same CSS rulesThe next problem I have spotted was that the same CSS rules are repeated over and over (e.g. for each Problem 6 - cleaning up and fixing indentation of HTMLSince I was happy with the result, I moved to HTML. It looked like a mess, mostly because the Problem 7 - filters breaking CSSSince there is a chance that in some circumstances filters mentioned above may break CSS in the snippet, I've made all of them optional. You can disable them from the Settings menu. Can I copy a website HTML code?Copy the HTML: Press the CTRL+C shortcut to copy, or right-click on your selected text and click Copy. 5. Create a new page in your Site. Add a new Content Block on the page.
How do I copy a website using CSS?First, hover over the element you want to copy. Then, right-click on it and choose the option “Inspect”. On the left side is the HTML DOM tree, and on the right side, the CSS styles of the selected element. Having the right element selected on the HTML DOM tree, right-click on it and choose “Copy” > “Copy styles”.
How do I copy a whole website?To duplicate a website, click Clone App/Create Staging. A popup will appear asking if the customer wants to Clone App or Create Staging. Click the dropdown and select the server on which you want to create a copy of the website and click Continue. The Cloudways Platform takes a few minutes to copy a website.
How do I copy and paste HTML code to my website?Highlight the embed code, then copy it to your clipboard. In your content management system, open up your HTML viewer. Paste the HTML snippet you just copied into your HTML viewer window. Then click 'OK' or 'Save.
|