I would like to format my code by myself so it is easier for me to read the code, rather than having SharePoint formatting my code automatically, and it is hard to read.
-
1How do you insert your code? There are so many methods and different language to insert code. – Mark L Nov 16 '15 at 3:49
-
I use edit source in the web browser – Zul Hazmi Nov 16 '15 at 3:51
-
4short answer, you can't. get used to it. – Eric Alexander Nov 16 '15 at 4:01
Just use a decent development tool like Visual Studio. To use the browser for developing is like using scissors for mowing you lawn
Hint: a very good, free and lightweigt Development Tool for SharePoint Development on the Server is Visual Studio "Code": https://code.visualstudio.com/
Another one is Notepad++: https://notepad-plus-plus.org/
If you are talking about Code within sharepoint: It is the same here: Just don't! Create content editor Webparts and include the code into external files (which you edit with a proper development tool).
Alas, You can't, get used to it (in the comments section) is NOT the 100% correct answer...
View Formatted HTML source
In Interner Explorer you can change the default viewer to any application you want.
http://www.online-tech-tips.com/internet-explorer-tips/change-ie-view-source-program/
So View Source can look like:
http://onlinetechtipscom.c.presscdn.com/wp-content/uploads/2009/03/sublime-code-editor.jpg
BUT.. you can only View, not edit
Edit SharePoint files in other application
Most SharePoint pages and files are in document libraries you can Open With Eplorer (can only be done with IE)
you can open and save those with any application you want.
Note that those applications will not deal with Check-In/Out situations like SP Designer can.
(I usually turn Check-In/Out off on the Style Library
and _catalogs/masterpage
when I am doing major work)
You can map document libraries as Network Share:
- https://kb.intermedia.net/article/1603
- http://www.viewmaster365.com/365coach/#/Map_Document_Libraries_as_Network_Shares
Once mapped the connection is persistent and you do need to work with IE.
I only use IE to establish such connections (required about once a week) and primarily work with other file Editors
Since SP2013 you only have to deal with HTML files for MasterPages and DisplayTemplates (they are created automatically by SP)
(as I am a Frontend Dev) I prefer developing in Adobe Brackets, I hardly ever open SharePoint Designer.
Update 1
I am so not used to putting code INSIDE webparts I mis-read the question
Putting code inside WebParts is not a good practice as it hides your code all over the place, is only accesible with the SharePoint UI and can't be reused. If you link CEWPs to files its all a lot easier.
Now to answer the question
You CAN format that code if you install some extra software which turns the TEXTAREA
into a decent editor.
It just takes some work:
- Create a BookMarklet or GreaseMonkey script to change the TEXTAREA
using - TinMCE
See: https://stackoverflow.com/questions/18702148/add-a-code-editor-to-a-textarea-via-console-bookmarklet
or try
(same concept but with a local install)
-
2All of this is grand but OP stated he was editing code via "Edit Source" - this is an option in the Ribbon to edit the HTML field source of a page. – James Love Nov 16 '15 at 14:37
-
My mistake... Best Pratice: Link Content from ContentEditorWPs to files (and use any editor you want) We got the whip if we put code inside them – Danny '365CSI' Engelman Nov 16 '15 at 14:42