Beispiel #1
0
        public string Javascript(string js)
        {
            if (OptionsManager.CurrentOptions.DisableCodeFormatting)
            {
                return(js);
            }

            return(jsBeautifier.Beautify(js).Trim());
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("fukc: giev fiel");
                return;
            }

            var fileName = args[0];

            if (args[0].StartsWith("http://") || args[0].StartsWith("https://"))
            {
                Console.WriteLine("htpp? ok. gon dolwnod fiel.");
                try
                {
                    fileName = "./6obcy.js";

                    using (var wc = new WebClient())
                        wc.DownloadFile(args[0], "./6obcy.js");
                }
                catch
                {
                    Console.WriteLine("fukc: fiel dlownad falied");
                    return;
                }
            }

            if (!File.Exists(fileName))
            {
                Console.WriteLine("fukc: giev crorcet fiel ok?");
                return;
            }

            Console.WriteLine("gon ask bro for hepl ok?");

            Console.WriteLine("---");
            var src   = new ObcySourceFile(fileName);
            var deobf = src.Deobfuscate();

            Console.WriteLine("---");

            Console.WriteLine("thank bro! will prietifey.");
            var beautifier = new Beautifier();

            var actuallyReadableCode = beautifier.Beautify(deobf);

            File.WriteAllText(
                Path.GetFileNameWithoutExtension(src.FileName) + ".deobf.js",
                actuallyReadableCode
                );

            Console.WriteLine("im outta here.");
        }
Beispiel #3
0
        /// <summary>
        /// Outputs the script converted into a beautiful form.
        /// </summary>
        /// <returns></returns>
        public JsScript GetFormattedScript()
        {
            if (IsFormatted)
            {
                return(this);
            }

            var tool = new Beautifier(new BeautifierOptions {
                IndentWithTabs = false, IndentSize = 4
            });
            var pretty = tool.Beautify(RawCode);

            return(new JsScript(pretty, Url, IsEmbeddedInHtml, EmbeddedLine, EmbeddedColumn)
            {
                IsFormatted = true
            });
        }
Beispiel #4
0
        void init_with_code(string js_code, int line, int column, bool no_pretty)
        {
            inits();
            InitializeComponent();

            textEditor.Options.EnableHyperlinks     = false;
            textEditor.Options.HighlightCurrentLine = true;
            textEditor.Options.ConvertTabsToSpaces  = true;
            textEditor.PreviewMouseLeftButtonDown  += TextEditor_PreviewMouseLeftButtonDown;

            var bb = new Beautifier(new BeautifierOptions {
                IndentWithTabs = false, IndentSize = 4
            });

            raw    = js_code;
            pretty = bb.Beautify(raw);

            try
            {
                var p1 = new JavaScriptParser(raw, new ParserOptions {
                    Loc = true
                });
                var p2 = new JavaScriptParser(pretty, new ParserOptions {
                    Loc = true
                });
                s1 = p1.ParseScript(true);
                s2 = p2.ParseScript(true);

                if (line == -1 || column == -1)
                {
                    (l, c) = (1, 1);
                }
                else
                {
                    (l, c) = (line, column);
                }
                this.no_pretty = no_pretty;

                Loaded += ScriptViewer_Loaded;
            }
            catch
            {
                Beautify.IsEnabled = false;
                textEditor.Text    = raw;
            }
        }
        public void Beautify()
        {
            Beautifier b = new Beautifier(new BeautifierOptions
            {
                BraceStyle              = BraceStyle.Expand,
                BreakChainedMethods     = false,
                EvalCode                = true,
                IndentChar              = '\t',
                IndentSize              = 1,
                IndentWithTabs          = true,
                JslintHappy             = true,
                KeepArrayIndentation    = true,
                KeepFunctionIndentation = true,
                MaxPreserveNewlines     = 1,
                PreserveNewlines        = true
            });

            scintilla.Text = b.Beautify(scintilla.Text);
        }
Beispiel #6
0
        private void GenerateQuery(RequiredDataContainer Container, string Database)
        {
            QueryableEntity Aluno    = new QueryableEntity(Container.EntityRelationshipModel.FindByName("Aluno"));
            QueryableEntity Endereco = new QueryableEntity(Container.EntityRelationshipModel.FindByName("Endereco"));

            RelationshipJoinOperator RJoinOp = new RelationshipJoinOperator(
                Aluno,
                (Relationship)Container.EntityRelationshipModel.FindByName("AlunoMora"),
                new List <QueryableEntity>()
            {
                Endereco
            },
                Container.ERMongoMapping);

            SortArgument SortArg = new SortArgument(Aluno, Aluno.Element.GetIdentifierAttribute(), MongoDBSort.Ascending);
            SortStage    SortOp  = new SortStage(new List <SortArgument>()
            {
                SortArg
            }, Container.ERMongoMapping);

            List <AlgebraOperator> OperatorList = new List <AlgebraOperator>()
            {
                RJoinOp, SortOp
            };

            FromArgument FromArg = new FromArgument(Aluno, Container.ERMongoMapping);

            QueryGenerator QueryGen = new QueryGenerator(FromArg, OperatorList);

            string Query = QueryGen.Run();

            Beautifier jsB = new Beautifier();

            queryBox.Text = jsB.Beautify(Query);

            QueryRunner QueryRunner = new QueryRunner("mongodb://localhost:27017", Database);

            string Result = QueryRunner.GetJSON(Query);

            resultBox.Text = Result.PrettyPrintJson();
        }
Beispiel #7
0
        public void Accept(ICodeFormatterVisitor visitor)
        {
            foreach (ICodeFormatterAcceptor acceptor in Model.VariableActionModel)
            {
                acceptor.Accept(visitor);
            }
            foreach (ICodeFormatterAcceptor acceptor in Model.MainActionModel)
            {
                acceptor.Accept(visitor);
            }
            Beautifier beautifier = new Beautifier();

            beautifier.Opts.IndentSize           = 4;
            beautifier.Opts.IndentChar           = ' ';
            beautifier.Opts.PreserveNewlines     = true;
            beautifier.Opts.JslintHappy          = false;
            beautifier.Opts.KeepArrayIndentation = false;
            beautifier.Opts.BraceStyle           = BraceStyle.Collapse;
            beautifier.Flags.IndentationLevel    = 0;
            beautifier.Opts.BreakChainedMethods  = false;
            CodeOutput = beautifier.Beautify(visitor.CodeOutput);
        }
 public void TestTabs()
 {
     Assert.AreEqual(beautifier.Beautify("{tabs()}"), "{\n\ttabs()\n}");
 }
        public bool JSBeautifier(Document document)
        {
            if (document == null ||
                document.Type != "Text" ||
                document.Language == null ||
                document.Language == "Plain Text"
                )
            {
                return(false);
            }

            var oldActiveDocument = Dte.ActiveDocument;

            try
            {
                document.Activate();

                var languageOptions = Dte.Properties["TextEditor", document.Language];
                var insertTabs      = (bool)languageOptions.Item("InsertTabs").Value;
                var isFilterAllowed = OptionsPage.AllowDenyFilter.IsAllowed(document.Name);

                var vsTextView = GetIVsTextView(document.FullName);
                if (vsTextView == null)
                {
                    return(false);
                }

                var wpfTextView = GetWpfTextView(vsTextView);
                if (wpfTextView == null)
                {
                    return(false);
                }

                _undoHistoryRegistry.TryGetHistory(wpfTextView.TextBuffer, out var history);

                using (var undo = history?.CreateTransaction("JSBeautify"))
                {
                    vsTextView.GetCaretPos(out var oldCaretLine, out var oldCaretColumn);
                    vsTextView.SetCaretPos(oldCaretLine, 0);

                    var snapshot = wpfTextView.TextSnapshot;

                    using (var edit = snapshot.TextBuffer.CreateEdit())
                    {
                        string text = snapshot.GetText();

                        var beautifier = new Beautifier();

                        beautifier.Opts.IndentSize = 4;
                        beautifier.Opts.IndentChar = ' ';

                        beautifier.Opts.PreserveNewlines = true;
                        beautifier.Opts.JslintHappy      = true;

                        beautifier.Opts.KeepArrayIndentation    = true;
                        beautifier.Opts.KeepFunctionIndentation = false;

                        beautifier.Opts.BraceStyle          = BraceStyle.Collapse;
                        beautifier.Opts.BreakChainedMethods = false;

                        beautifier.Flags.IndentationLevel = 0;

                        text = beautifier.Beautify(text);

                        edit.Replace(0, snapshot.Length, text);

                        edit.Apply();
                    }

                    vsTextView.GetCaretPos(out var newCaretLine, out var newCaretColumn);
                    vsTextView.SetCaretPos(newCaretLine, oldCaretColumn);

                    undo?.Complete();
                }
            }
            finally
            {
                oldActiveDocument?.Activate();
            }

            return(true);
        }