質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
HTML5

HTML5 (Hyper Text Markup Language、バージョン 5)は、マークアップ言語であるHTMLの第5版です。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

Q&A

1回答

4405閲覧

VSCodeでのHTMLのコード整形のルール変更について

makition

総合スコア11

HTML5

HTML5 (Hyper Text Markup Language、バージョン 5)は、マークアップ言語であるHTMLの第5版です。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

0グッド

0クリップ

投稿2019/09/26 14:29

編集2019/09/27 02:32

現状のHTMLのコード整形について

html

1<!DOCTYPE html> 2<html> 3 <head> 4 </head> 5 <body> 6 this is the main page. 7 </body> 8</html>

となるようにしたいが、

html

1<!DOCTYPE html> 2<html> 3<head> 4</head> 5<body> 6 this is the main page. 7</body> 8</html>

コードを保存すると(保存時に整形)このようにタグが全て左寄せになってしまう。

setting.jsonについて

json

1{ 2 // ウィンドウ設定 3 "window.zoomLevel": -1, // 拡大率 4 "window.title": "${activeEditorShort}${separator}${rootName}", 5 // エディター設定 6 "editor.codeLens": false, 7 "editor.lineHeight": 28, 8 // "editor.fontFamily": "Inconsolata-g", 9 // "editor.fontSize": 14, 10 "editor.fontFamily": "Hasklig, Consolas, 'Courier New', monospace", 11 "editor.fontLigatures": true, 12 "editor.fontSize": 15, 13 "editor.glyphMargin": true, // 行の左端に余白を作る 14 "editor.roundedSelection": true, // 選択範囲の角を丸める 15 "editor.quickSuggestions": { 16 "comments": false, // コメント内では無効 17 "other": true, // その他の場所で有効 18 "strings": true // 文字列内では有効 19 }, 20 "editor.folding": true, // コードの折りたたみを許可 21 "editor.lineNumbers": "on", 22 "editor.minimap.enabled": true, 23 "editor.minimap.maxColumn": 40, 24 "editor.insertSpaces": true, // Tabキーで半角スペースを入力 25 "editor.renderIndentGuides": true, // インデントのガイドラインを表示 26 "editor.minimap.side": "right", // ミニマップを右に表示 27 "editor.autoIndent": false, // オートインデント 28 "editor.cursorStyle": "block", 29 "editor.cursorWidth": 3, 30 "editor.cursorSmoothCaretAnimation": true, 31 "editor.emptySelectionClipboard": true, // 選択範囲無しでのコピーを許可 32 "editor.links": true, // リンクをクリック可能に 33 "editor.matchBrackets": true, // 対応する括弧の強調表示をオンに 34 "editor.mouseWheelScrollSensitivity": 0.7, // マウスホイール回転の移動係数 35 //"editor.suggestFontSize": 24, // サジェストの文字サイズ 36 "editor.suggestLineHeight": 24, // サジェスト欄の行の高さ 37 "diffEditor.renderSideBySide": false, // Git の差分を行内に表示 38 "editor.colorDecorators": false, // カラーデコレーターを非表示 39 "editor.formatOnPaste": true, // ファイル保存時に自動でフォーマット 40 "editor.formatOnType": true, // 入力した行を自動でフォーマット 41 "editor.formatOnSave": true, 42 "editor.minimap.renderCharacters": false, // ミニマップの表示文字をブロックに変更 43 "editor.minimap.showSlider": "always", // 表示領域をミニマップで常にハイライト 44 "editor.multiCursorModifier": "ctrlCmd", // マウスでの複数選択時の修飾キーを変更 45 "editor.renderControlCharacters": true, // 制御文字を表示 46 "editor.renderLineHighlight": "all", // 選択行を行番号含めすべてハイライト 47 "editor.renderWhitespace": "all", // エディターの幅で折り返し 48 "editor.trimAutoWhitespace": false, // 改行時に空行のインデントを保持する 49 "editor.cursorBlinking": "smooth", 50 // ターミナル 51 "terminal.integrated.fontSize": 14, 52 // emmet 53 "emmet.showSuggestionsAsSnippets": true, // Emmet の候補を表示 54 "emmet.triggerExpansionOnTab": true, // TAB キーで Emmet を展開できるようにする 55 "emmet.variables": { 56 // Emmet で展開される HTML の言語を変更 57 "lang": "ja" 58 }, 59 // ファイル設定 60 "explorer.confirmDelete": false, // ファイル削除時の確認を表示しない 61 "files.associations": { 62 "*.c": "c", 63 "*.cpp": "cpp", 64 "*.cs6": "csharp", 65 "*.cs7": "csharp" 66 }, 67 "files.exclude": { 68 "**/*.map": true, 69 "**/node_modules": true, 70 "**/.classpath": true, 71 "**/.project": true, 72 "**/.settings": true, 73 "**/.factorypath": true 74 }, // ファイルの保存時に末尾を改行 75 "files.trimFinalNewlines": true, // ファイルの保存時に最終行以降をトリミング 76 "files.trimTrailingWhitespace": true, // ファイルの保存時に行末の空白をトリミング 77 "files.autoGuessEncoding": true, // 文字コードを自動判断 78 "files.autoSave": "afterDelay", 79 "files.autoSaveDelay": 1000, 80 "html.format.contentUnformatted": "pre, code, textarea, title, h1, h2, h3, h4, h5, h6, p", // タグ内の記述はフォーマットしない 81 "html.format.extraLiners": "", // head, body, /html タグの前に改行を入れない 82 "html.format.unformatted": null, // フレージング・コンテンツ(旧インライン要素のようなタグ)はフォーマットしない 83 "html.format.wrapLineLength": 0, // 行の文字数制限を無くし自動で改行させない 84 "search.exclude": { 85 // 検索対象外にするファイル設定( files.exclude のファイルも含む) 86 "**/tmp": true 87 }, 88 //"window.openFoldersInNewWindow": "on", // 新規ワークスペースを別ウインドウで開く 89 "workbench.editor.showTabs": true, // アクティビティバー(左端)を非表示に 90 "workbench.editor.tabSizing": "shrink", // タブが多い場合,文字を非表示にしてもタブ表示を優先する 91 "workbench.statusBar.visible": true, // ステータスバー(下端)を表示 92 "workbench.sideBar.location": "left", // サイドバーを左に 93 "workbench.startupEditor": "none", // Welcome Page を表示しない 94 // クラッシュレポートを送信する 95 "telemetry.enableCrashReporter": true, 96 "telemetry.enableTelemetry": true, 97 // 拡張機能関連 98 "extensions.autoUpdate": true, 99 "extensions.ignoreRecommendations": false, 100 "C_Cpp.default.cppStandard": "c++14", 101 "C_Cpp.default.cStandard": "c11", 102 "terminal.explorerKind": "external", 103 "terminal.integrated.cursorStyle": "line", 104 "C_Cpp.clang_format_style": "file", 105 "C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: K&R, IndentWidth: 4}", 106 // Whether to lint Python files. 107 "python.linting.enabled": true, 108 // Whether to lint Python files using pylint. 109 "python.linting.pylintEnabled": false, 110 "python.linting.flake8Enabled": true, 111 "python.linting.lintOnSave": true, 112 "python.linting.flake8Args": [ 113 "--ignore=W293, W504, E501", // 空行に空白があるとWarningが出るW293はエディタのコード整形が引っかかるためOFF, +のオペレータのあとで改行すると引っかかるW504もOFF 114 ], 115 "python.formatting.provider": "autopep8", 116 "python.formatting.autopep8Args": [ 117 "--aggressive", 118 "--aggressive", 119 "--max-line-length", 120 "160", // Pythonのmaxlength設定 121 ], 122 // 言語別設定 123 "[markdown]": { 124 "files.trimTrailingWhitespace": false, // Markdown のファイルは行末の空白をトリミングしない 125 // markdownでスニペットが表示されないのを回避 126 "editor.wordWrap": "on", 127 "editor.quickSuggestions": true, 128 "editor.snippetSuggestions": "top", 129 "editor.tabSize": 2, 130 "diffEditor.ignoreTrimWhitespace": true, 131 "files.trimFinalNewlines": false, 132 "editor.trimAutoWhitespace": false, 133 }, 134 "markdown.preview.breaks": true, 135 // JavaScriptでのみ保存時フォーマットを有効化 136 "[javascript]": { 137 "editor.formatOnSave": true, 138 "editor.tabSize": 4 139 }, 140 // prettierのシングルクォーテーションオプションをon 141 "prettier.singleQuote": true, 142 "prettier.disableLanguages": [ 143 "vue", 144 "markdown", 145 ], 146 "[javascriptreact]": { 147 "editor.formatOnSave": true, 148 "editor.tabSize": 2 149 }, 150 "[plaintext]": { 151 "files.insertFinalNewline": false 152 }, 153 "[cpp]": { 154 "editor.quickSuggestions": true 155 }, 156 "editor.acceptSuggestionOnEnter": "off", 157 "C_Cpp.intelliSenseEngineFallback": "Disabled", 158 "clang.executable": "clang++", 159 "clang.cxxflags": [ 160 "-std=c++14" 161 ], 162 "clang.cflags": [ 163 "-std=c11" 164 ], 165 "editor.snippetSuggestions": "inline", 166 "csharpfixformat.style.braces.onSameLine": false, 167 "csharp.format.enable": false, 168 "C_Cpp.autocomplete": "Disabled", 169 "path-intellisense.extensionOnImport": true, 170 "editor.detectIndentation": false, 171 "editor.suggestSelection": "first", 172 "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue", 173 "java.errors.incompleteClasspath.severity": "ignore", 174 "C_Cpp.updateChannel": "Insiders", 175 "workbench.colorTheme": "SynthWave '84", 176 "python.jediEnabled": false, 177 "editor.wordWrap": "on", 178 "files.insertFinalNewline": true, 179 "editor.scrollBeyondLastLine": true, 180 "workbench.iconTheme": "simple-icons", 181 "python.pythonPath": "/usr/local/opt/python/bin/python3.7", 182}

質問

  • 何か拡張機能を入れれば解決出来るのだろうか?
  • html用のフォーマッターとして何か記述すべきか、導入すべきか
  • キー入力でコード整形をするにも上記のようになってしまうし、保存時の整形で綺麗にしたい。

拡張機能について

  • Auto Close Tag
  • Auto Rename Tag
  • Beautify
  • Bracket Pair Colorizer2
  • indent rainbow
  • Prettier
  • Visual Studio IntelliCode

他にも入れてますが、Pythonなどの関係が明らかになさそうなものはとりあえず省いてます。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

oikashinoa

2019/09/26 23:23

setting.jsonもmarkdownのcodeとして本文に記載し直してください。あと機能拡張入れてるので何を入れたかも記載したほうが良いです。
oikashinoa

2019/09/27 05:49 編集

BeautifyとPrettierはフォーマッタだと思います。全て無効化したり一つだけ有効にして切り分けてから質問すると良いと思います。
mouse_484

2019/09/28 12:53

Visual Studio Codeの質問なのでVisual Studio Codeタグをつけてください
guest

回答1

0

Prettierが導入されているようなので
HTMLコードで右クリックをしHTMLをフォーマット..からPrettierを選択してください

Prettierの初期設定であればうまく動作します

投稿2019/09/28 12:52

mouse_484

総合スコア759

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問